Tuesday, June 21, 2016

The basics of Collection in Java

Collection, this may be another most advanced section in Java. I think you may heard that there are so many things to learn about Collections. Lets begin our journey.

What is the Collection & Collection framework ?

  • Collection is a just a collection of objects or data.
  • Java collection framework is a architecture which is used to manage collections in Java.
  • Java Collection framework is consist of interfaces, implementations and also algorithms.

Core collection interface hierarchy

As you can see, Map is a separate collection interface. Because it stores values with a key.

Advanced collection hierarchy

Click on image for clear view

Click on image for clear view

How to select which Collection is needed ?

Collection hierarchy is a big one, but you can identify it easily. Look at the following diagram. Begin with the blue color checking statement.

Click on image for clear view

Collection vs Collections

  • Collection is a interface and it is the root interface of Java Collection framework.
  • Coillections is a utility class which is from java.util package.
  • Collections class consist of core methods that can be used commonly with List, Set and Queue. 
  • There are so many methods which are defined in Collections class.

List vs Set vs Queue vs Map

Click on image for clear view

Advantages of using Collection framework 

  • No need to learn new APIs or create new APIs.
  • Increase speed and interoperability.
  • Reduce programming effort.
  • It increase software reuse. 

No comments:

Post a Comment