Untitled Document

Subscribe here to get updates on new Videos

 

1. Need of Collection Framework?

 

 

 

homenext

 

An array is an indexed Collection of fixed number of homogeneous data elements.

The Main advantage of Arrays is we can represent multiple values with a single variable.

So that reusability of the code will be improved.

Limitations of Object type Arrays:

Arrays are fixed in size i.e. once we created an array with some size there is no chance of increasing its size based on our requirment. Hence to use arrays compulsory we should know the size in advance which may not possible always.

Arrays can hold only homogeneous data elements


Example:

Student[] s=new Student[10000];
s[0]=new Student; (correct)
s[1]=new Customer(); (wrong)

But We can resolve this problem by using object Arrays.
Object[] o=new Object[10000];
o[0]=new Student();
o[1]=new Customer();

Arrays Concept is not implemented based on some standard data structure hence readymade method support is not available for every requirment we have to write the code explicitly. Which is complexity of programming.

To overcome the above limitations of Arrays we should go for Collections.

Collections are growbable in nature. i.e. Based on our requirment we can increase (or) Decrease the size.
Collections can hold both homogeneous & Heterogeneous elements.
Every Collection class is implemented based on some standard data structure. Hence readymade method support is available for every requirement. Being a programmer we have to use this method and we are not responsible to provide implementation