The basics of Collection in Java

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

What is the Collection & Collection framework?

  • The collection is just a collection of objects or data.
  • The Java collection framework is an architecture that is used to manage collections in Java.
  • The Java Collection framework consists 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

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

List vs Set vs Queue vs Map

Click on image for clear view

Advantages of using the Collection framework 

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

The basics of Collection in Java The basics of Collection in Java Reviewed by Ravi Yasas on 4:26 PM Rating: 5

No comments:

Powered by Blogger.