Java Collection Interfaces Tutorial
The Java Collection Interface is the foundation of the Java Collection Framework. It defines the core methods that all collections must implement. Understanding these interfaces and their specific characteristics is crucial for choosing the right collection type for your data.
List Interface
List interface extends the Collection interface. It is an ordered collection of objects.
It allows duplicate values.
We can access elements from the list by the index (position) of the element.
Classes implementing List: ArrayList, LinkedList, Vector, Stack.
Set Interface
Set interface extends the Collection interface. It is an unordered collection of objects.
It does not allow duplicate values.
It models the mathematical set abstraction.
Classes implementing Set: HashSet, LinkedHashSet, TreeSet.
Queue Interface
Queue interface extends the Collection interface. It is used to hold the elements which are about to be processed.
It follows the FIFO (First In First Out) principle mostly.
Classes/Interfaces extending/implementing Queue: PriorityQueue, Deque, ArrayDeque.
Map Interface
Map interface is not a valid subtype of the Collection interface. But it is part of the collection framework.
It stores data in Key and Value pairs.
It does not allow duplicate keys.
Classes implementing Map: HashMap, LinkedHashMap, TreeMap, Hashtable.