Collection: It is an object that represents a group of objects.
Java Collections Framework is all about how we store group of objects and manipulate them.
Why we need Collections
It reduces the programming effort and increases performance while providing high interoperability.
The Java Collection Framework in a nutshell
- Set, List, and Queue interfaces extend the Collection interface.
- The Set interface is implemented by HashSet, LinkedHashset classes. The Set interface is extended by the Sorted Set interface and it is implemented by the Treeset.
- The List interface is implemented by ArrayList, Vector, and LinkedList classes.
- The Queue interface is extended by Priority Queue and LinkedList classes. The LinkedList is implements both the List and the Queue interfaces.
Then we have the Map interface which is separated from the Collections interface. It stores the values as key, value pairs.
- The HashTable, Hashmap, and LinkedHashmap directly implement the Map interface.
- The Sorted Map interface extends the Map interface and it is implemented by the Treemap.
The Common methods for Collections.
Attributes of each
What are the common exception that we can get:
- NullPointer Exception
- ClassCast Exception