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
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEganATW1v_cmIYFDlyS9MjJqWdXRge3wobTn0-ql6JJhOz02KNGNhWvMkuSKr7VbSBmrjQ5W_VHliQY9qcOeS_AKvScrUs0rTJ_ovuDVUnSxUJjMWF9Q0a16qBSCH5RJYYRuFzBicDt8JrN/s640/6.jpg) |
Click on image for clear view |
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhxDrN-UNOOlNXSiAi2-wCLnqe4QMQ3qip1dqRRjmRLr2dYBpYnjwv7FmPfta8dWuEVP1dy0cjhDYP6hWk33BfRkefLZWTLjGuS8J2N8kxLIsR5OEAkZP42T9XsulWLf2VqHz44BJkPvMOq/s400/7.jpg) |
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.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgL1v8sJopYNaMhTzSfvoOkqxMMFYGqpD9CxTU9Un-06sHWrhlrnSIc9BluTc87yp7NMpL9B8N3heOSROiaURVfy57AOUxtVDbp8MNTLXQQ1pVrPhT60LgeTkyYzqiY7-KlDKisLE63Lnhe/s640/3.jpg) |
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
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjKGk-UTYBPoyd8W9VxvcQx077XW8hvtCHERjI_7ffXOQnabq4zni0vnJQ5JVOWBoxGpfFm3bsBYE8O3-M4YC3oTITUTr0N7ZoXSZBrfZNknWCvAi1DFpf6cpJBdugo56Wn2mDNzMBTIyQL/s640/8.jpg) |
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.
No comments: