ddsingh@infomatics.info +91 9760014754

Need of Collection Framework

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 Arrays

1)Fixed in Size

2)Homogenous Data

3)No Underlying Data Structure

1)Fixed In Size:-

 Arrays are fixed in size i.e. once we created an array

With some size there is no chance of increasing or decreasing it’s size based on our requirement. Hence To use arrays compulsory we should know the size in

Advance which may not possible always.

 2)Homogenous Data:-

    Arrays can hold only homogenous data elements.

    Ex:-

   Student[] str=new Student[100];

   str[0]=new Student();   //OKK

   str[1]=new Customer(); //CTE

  But We Can Resolve this problem by creating an array of Object type.

 Ex:-

 Object[] arr=new Object[100];

  arr[0]=new Student();   //OKK

  arr[1]=new Customer(); //OKK

3)No Underlying Data Structure:-

 Arrays concept is not implemented based on some standard data structure hence ready made method 

 support is not available for every requirement so we have to write the code explicitly. Which is complexity of

 Programing.

Difference between Array and Collection
 

Arrays are fixed in size that is once we create an array we can not increased or decreased based on our requirement.

Collection are growable in nature that is based on our requirement. We can increase or decrease of size.

With respect to memory Arrays are not recommended to use.

With respect to memory collection are recommended to use.

With respect to performance Arrays are recommended to use.

With respect to performance collection are not recommended to use.

Arrays can hold only homogeneous data types elements.

Collection can hold both homogeneous  and  heterogeneous elements.

There is no underlying data structure for arrays and hence readymade method support is not available.

Every collection class is implemented based on some std data structure and hence for every requirement readymade method support is available being a programmer. we can use these method directly and We are not responsible to implement these methods.

Arrays can hold both object and primitive.

Collection can hold only object types but primitive can not.

 

 

 


Next