An array is an indexed collection of a fixed number of the homogeneous data element. The main advantage of arrays is we can represent a group of values with a single name so that readability of the code will be improved.
- Arrays Are Fixed In Size.
once we constructed/create an array there is no chance of increasing or decreasing array size based on our requirement
- Arrays Can Hold Only Homogeneous Data Elements.
Customer[] cust = new Customer[100];
cust[0] = new Customer();
cust[1] = new Customer();
cust[2] = new Client(); CE: In Compatable Type.
NB:
An array can hold the only same type of objects, by mistake, if we are trying to add another type of object then we will get compile time error.
We can overcome this limitation/problem by using Object[]
Object[] obj = new Object[100];
obj[0] = new Customer();
obj[1] = new Customer();
obj[2] = new Client();
Customer[] cust = new Customer[100];
cust[0] = new Customer();
cust[1] = new Customer();
cust[2] = new Client(); CE: In Compatable Type.
NB:
An array can hold the only same type of objects, by mistake, if we are trying to add another type of object then we will get compile time error.
We can overcome this limitation/problem by using Object[]
Object[] obj = new Object[100];
obj[0] = new Customer();
obj[1] = new Customer();
obj[2] = new Client();
- No Readymade data structure support.
There is no readymade data structure support available for arrays, for every requirement we should write the logic explicitly. So complexity will be increased. To overcome these problems we should go for Collection Frameworks.
- No Readymade data structure support.
There is no readymade data structure support available for arrays, for every requirement we should write the logic explicitly. So complexity will be increased. To overcome these problems we should go for Collection Frameworks.