Collection interface

Collection interface

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.

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.

That’s all about Collection interface in java. If you have any queries or feedback, please write us email at Enjoy learning, Enjoy Java.!!

Collection interface
Scroll to top