why we use Collection framework in Java?

Collection means group of objects
Framework means An architecture to manipulate data
i.e. Collection Framework provide a mechanism to manipulate the group of objects such as sorting, searching , managing etc.


  • We use Collections in Java because sometimes we need to deal with several objects at a time rather than a single one.
  • Not only Java but other languages/platforms have their "Collections" as well.
  • Collections framework gives us powerful data structures as well as algorithms to process them. Thanks to collections we can define unique objects among loads of other, sort objects in some specific order, perform look up amongst them and many-many-many other things.



  • Java's collection classes provides a higher level interface than arrays.
  • Arrays have a fixed size. Collections (see ArrayList) have a flexible size.
  • Efficiently implementing a complicated data structures (e.g., hash tables) on top of raw arrays is a demanding task. The standard HashMap gives you that for free.
  • There are different implementation you can choose from for the same set of services: ArrayList vs. LinkedList, HashMap vs. TreeMap, synchronized, etc.
  • Finally, arrays allow covariance: setting an element of an array is not guaranteed to succeed due to typing errors that are detectable only at run time. Generics prevent this problem in arrays.


No comments:

Post a Comment

AUTHOR