Collections are like containers that group multiple items in a single unit also Java Collections Framework is a collection of interfaces and classes which help in storing and processing the data efficiently. Collection Framework provides an architecture to store and manipulates the group of objects.
Collections are used almost in every programming language and when Java arrived, it also came with few Collection classes; Vector, Stack, Hashtable, Array. Java 1.2 provided Collections Framework that is architecture to represent and manipulate Collections in a standard way.
Hierarchy of Collection Framework
The above picture is showing the architecture of Java Collections. Boxes in orange shade are interfaces and boxes in sky blue shade are representing the classes.
Interfaces – Java Collections Framework interfaces provide the abstract data type to represent the collection. java.util.Collection is the root interface of Collections Framework. It is on the top of Collections framework hierarchy.
Classes – Java provides core implementation classes for collections. We can use them to create different types of collections in our program. Some important collection classes are ArrayList, LinkedList, HashMap, TreeMap, HashSet, TreeSet.These classes solve most of our programming needs.
List – A List is an ordered Collection (sometimes called a sequence). Lists may contain duplicate elements. Elements can be inserted or accessed by their position in the list, using a zero-based index.
Set – A Set is a Collection that can’t contain duplicate elements. There are three main implementations of Set interface: HashSet, TreeSet, and LinkedHashSet.
HashSet, which stores its elements in a hash table, is the best-performing implementation.
TreeSet, which stores its elements in a red-black tree, orders its elements based on their values; it is substantially slower than HashSet.
LinkedHashSet, which is implemented as a hash table with a linked list running through it, orders its elements based on the order in which they were inserted into the set.
Products from Amazon.in
Price: Out of stock
Price: INR 29,999.00
Price: INR 14,999.00
Queue – It represents an ordered list of objects just like a List, but its intended use is slightly different. A queue is designed to have elements inserted at the end of the queue, and elements removed from the beginning of the queue. Just like a queue in a supermarket.
We will learn about all these interfaces and classes in details in coming tutorials. The collection is vast and highly used Framework in Java programming, So practice it seriously. It will make your programming easy and helpful in an interview too.
If you liked this video, then please subscribe to our YouTube Channel for more video tutorials.