In this tutorial, we are going to discuss collection interface in java. It is a part of java.util package. It is one of the root interfaces of the Collection Hierarchy. Any class does not directly implement the Collection interface.
- If we want to represent a group of individual objects as a single entity, then we should go for the Collection interface.
- The Collection interface defines the most common general methods which can be applicable for any Collection object.
- The following is the list of methods present in the Collection interface.
boolean add(Object o); boolean addAll(Collection c); boolean remove(Object o); boolean removeAll(Object o); boolean retainAll(Collection c); // To remove all objects except those present in c. void clear(); boolean contains(Object o); boolean containsAll(Collection c); boolean isEmpty(); int size(); Object toArray(); Iterator iterator();
There is no concrete class which implements Collection interface directly.