Collection interface is the root interface of the Java collections framework.
There is no direct implementation of this interface. However, it is implemented through its subinterfaces like
For example, the
ArrayList class implements the
List interface which is a subinterface of the
Subinterfaces of Collection
As mentioned above, the
Collection interface includes subinterfaces that are implemented by various classes in Java.
1. List Interface
List interface is an ordered collection that allows us to add and remove elements like an array. To learn more, visit: Java List Interface.
2. Set Interface
Set interface allows us to store elements in different sets similar to the set in mathematics. It cannot have duplicate elements. To learn more, visit: Java Set Interface.
3. Queue Interface
Queue interface is used when we want to store and access elements in First In, First Out(FIFO) manner. To learn more, visit: Java Queue Interface.
Methods of Collection
Collection interface includes various methods that can be used to perform different operations on objects. These methods are available in all its subinterfaces.
add()- inserts the specified element to the collection
size()- returns the size of the collection
remove()- removes the specified element from the collection
iterator()- returns an iterator to access elements of the collection
addAll()- adds all the elements of a specified collection to the collection
removeAll()- removes all the elements of the specified collection from the collection
clear()- removes all the elements of the collection