limitations of object arrays
An array is an indexed collection of fixed number of homogeneous data elements.
The main limitations of Object Arrays are
- Arrays are fixed in size i.e once we created an array there is no chance of increasing or decreasing it’s size based on our requirement.
Arrays can hold only homogeneous data elements.
Student  s = new Student ;
s = new Student;
s = new Integer(10);//compile time error :can not convert Integer to Student
s = “abc”;//compile time error :can not convert String to Student
We can resolve this problem by using object Arrays.
Object  o = new Object ;
o = new Student;
o = new Integer(10);
o = “abc”;
i.e By using Object Arrays we can hold heterogeneous data elements.
For the Arrays there is no underlying Data Structure i.e for every requirement we have to code explicitly and there is no default ready made support(like sorting, searching).We can’t represent array elements in some sorting order by default. We can’t prevent duplicate
object insertion etc…
- Every collection class has implemented based on some data structure.Hence for every requirement ready made method support is possible.We can represent all the elements in some sorting order. We can prevent duplicate object insertion by default
To resolve the above problems of arrays, Sun people has introduced ‘collections concept’. Collections are grow able in nature i.e based on requirement we can increase or decrease the size.Collections can hold heterogeneous data elements also.
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|