Collections, as the name suggests is going to collect something. And since, java only deals with objects. The java Collections is going to hold objects.
Just think for a moment! If you were given the responsibility to manage the Student records in a school. What would you do?
You would create the above student class and start creating objects for every students. But there could be thousands of students in a school.
How would you sort the student objects if you are asked to sort the students by age?How would you find out who is the eldest student in the school?And so on..
To maintain this huge number, java Collections comes into picture.
Collection is a framework in java which has some inbuild classes and interfaces in it, that helps in effective searching, sorting, deletion, insertion etc of an object.
To make use of Java Collections, you have to put all your objects into the 'Collection'. And Collections framework will do the rest for you.
So, there is an interface called 'Collection' but it doesn't do the sorting, searching etc on the objects all by itself. It has a few more interfaces and classes which helps it perform the task. Let's look at the below hierarchy:
As we can see in the above diagram there are two interfaces List and Set which are the direct child of Collection Interface.
'List' can contain duplicates whereas 'Set' will never accept duplicates.
Also 'List' is indexed.
Whereas Set is not indexed.
Next, we will dig more on Lists. As we see two concrete implementations of Lists. i.e. ArrayList and LinkedList which we will be looking next.