Java Collection Interface
In this tutorial, we will find out about the Java Collection interface and its subinterfaces.
The Collection interface is the root interface of the Java collections framework.
There is no immediate execution of this interface. However, it is actualized through its subinterfaces like List, Set, and Queue.
For instance, the ArrayList class actualizes the List interface which is a subinterface of the Collection Interface.
Subinterfaces of Collection
As mentioned above, the Collection interface includes subinterfaces that are implemented by various classes in Java.
1. List Interface
The List interface is an arranged assortment that allows us to include and eliminate components like an array.
2. Set Interface
The Set interface allows us to store components in various sets like the set in mathematics. It can’t have copy components.
3. Queue Interface
The Queue interface is used when we want to store and access elements in First In, First Out(FIFO) manner.
Methods of Collection
The Collection interface incorporates different strategies that can be used to perform various procedure on objects. These techniques are accessible 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
Thanks for reading! We hope you found this tutorial helpful and we would love to hear your feedback in the Comments section below. And show us what you’ve learned by sharing your photos and creative projects with us.