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
As mentioned above, the
Collection interface includes subinterfaces that are implemented by various classes in Java.
List interface is an ordered collection that allows us to add and remove elements like an array. To learn more, visit: Java List 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.
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.
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