A Collections in Java is an object that can store a group of other objects. There is an another term of collection object is container object. Java Collections may store same type as well as different type of data.
Collection object does not store the physical copies of other objects because the objects are already available in memory. It simply stores the references of other objects into collection object.
Collections in Java contains different methods to perform different operations, for example, it stores, retrieves and manipulates data by using those methods.
Table of Contents
A collection framework is actually a class library which handles groups of objects and it defines several classes and interfaces, which represents group of objects as a single unit.
Basic Interfaces of Collection Framework
All the collection classes and interfaces are available in java.util package. Here is the following key interface of collection interface
|1||Collection||Collection Interface is a root interface of collection framework.|
|2||List||List preserves insertion order and can contain the duplicates.|
|3||Set||Set does not preserve insertion order and also does not contains the duplicates.|
|4||SortedSet||SortedSet does not preserve insertion order and does not contain duplicates, but stores the elements in some sorting order.|
|5||Queue||Holds elements prior to processing.|
|6||Map||Map stores a group of objects but in the form of key-value pairs.|
|7||SortedMap||Stores a group of objects as key-value pairs, but according to some sorting order.|
Advantages of Collections over Arrays in Java
There are following key advantages of collections over arrays which are as follow:
- Size of collection can be increase or decrease because collections are growable in nature.
- Collections can hold multiple types of objects homogeneous as well as heterogeneous.
- In every collection there are some ready-made method support is available, because of those methods we can manipulates the data.
Memory point of view Collections is better than Array concept.
Performance point of view Array concept is better than Collections.
In conclusion, the programmer should decide which collection is helpful for handling the data plan he is creating in his software.