What are basic interfaces of Java Collections Framework
Below are core collections of java interfaces which encapsulate different types of collections. These are the interfaces that allow collections to be manipulated individually of the details of their representation. Java core collection interfaces are foundation of the Java Collections.
Below are list of core collection interfaces and its description:
- Collection – It is root of the collection hierarchy. Collection always represents group of objects also known as its elements. All collection behaves differently for example some types of collections allow duplicate elements but others do not. Some will be ordered and others are unordered. Java platform do not provide any direct implementations of this interfaces but provides implementations in more specific sub interfaces such as Set and List
- Set – its collection and cannot contain duplicate elements. This interface models mathematical set abstraction and is used to represent sets of elements, such as books on different topic, employee in a companies.
- List – it’s ordered collection also sometimes we call it sequence. Duplicate element allowed in Lists. User of a List generally has control over where in the list each element has been inserted and that can be accessed by their integer index (position).
- Queue – it’s collection that used to hold multiple elements prior to its processing. It provides all basic Collection operations and Queue provides additional functionality extraction, insertion and inspection operations.It typically, but not necessarily, orders the elements in a FIFO (first-in, first-out) method. Amongst exceptions are priority queues using which order elements according to supplied comparator or elements natural, ordering. Whatever ordering we used but head of queue would be the element that would be removed by a call to remove or using poll. In FIFO queue all new elements would be inserted at the tail of the queue.
- Deque – its collection that used to hold multiple elements prior to its processing. Moreover basic Collection operations Deque provides extra extraction, insertion and inspection operations. It can be use both as FIFO (first-in, first-out) and also LIFO (last-in, first-out). In deque all the new elements could be retrieved, inserted and removed at both ends.
- Map – It’s object which maps keys to its values. Map could not contain duplicate keys and each key could map to at least one value. If you used Hashtable before then you’re already familiar with the basics of Map because its same behavior.
Below are last two core collection interfaces which are sorted versions of Set and Map:
- SortedSet – it’s set that maintains its elements in the ascending order. Several other additional operations are also provided to take advantage of ordering. Sorted sets can be used for naturally ordered sets, such as making word lists and employee rolls.
- SortedMap – it’s Map that maintains mappings in ascending key order. Basically its Map equivalent of SortedSet. It’s used for naturally ordered collections of key and value pairs. For example: dictionaries and telephone directories.