Monday 8 February 2016

Why collection framework?

Why collection framework:
=======================
Before going to discuss collection framework,lets have a discussion on existing problems

1.Arrays are fixed  in size i.e once we create an array we can not increase or decrease the size.
2.Arrays can hold only homogeneous type of elements only i.e heterogeneous elements are not allowed,
if we are trying to store different type of elements we will get compile time error.
int mp = new int[25];
mp[0]=10;
mp[1]=12;
m[2]="hello";======>compile time error
     To over come this problems we can go for collection framework
1.Collections are growable in nature ie we can increase and decrease the size based on our requirement.
2.Collections allows both homogeneous and heterogeneous elements.
3.Collections are bunch of pre defined methods.
ex: like add(),remove().........

No comments:

Post a Comment