Limitations of object Arrays
- An array is an indexed collection of fixed number of homogeneous data elements.
- The main advantage of arrays is we can represent any number of values by using single name.
int[ ] x=new int;
By using x variable we can represent 600 values.By means of index we can differentiate values.
The main limitations of Object Arrays are
- Arrays are fixed in size i.e based on our requirements we can’t increase or we can’t decrease the size.hence with respect to memory arrays shows worst performance
- Arrays can hold only homogeneous data elements.
Student  s = new Student ; s = new Student();----->//valid s = new Customer();---->//invalid
But we can resolve this problem by using object arrays.
Object a=new Object; a = new Student();----->//valid a = new Customer();---->//valid
- There is no underlying data structure for arrays hence for every requirement we have to code manually and automatic method support is not available.
We can resolve the above problems by using the Collections
- Collections are growable in nature i.e Based on our requirement we can increase/decrease the size.Hence with respect to memory Collections shows excellent performance
- Collections can hold both heterogeneous and homogeneous objects
- Collections are built based on some data structures hence for every requirement automatic method support is available
Comparison between Collections and Arrays
|Collections are not fixed In size||Arrays are fixed In size|
|With respect to memory collections are good||with respect to memory arrays are not good|
|With respect to performance collections shows worst performance||With respect to performance the arrays are recommended to use|
|Collections can hold heterogeneous data elements||Arrays can only hold homogeneous data elements|
|Every Collection class has built by using some Data structure||There is no underlying Data Structure|
|Collection can hold only Objects but not primitives||Arrays can hold both Objects and primitives|