The Collection interface provides a set of common methods that are available to most collection types in the Java Collection Framework. These methods allow developers to perform basic operations such as adding, removing, searching, and managing elements in a collection.
1. add(E element)
Adds an element to the collection.
collection.add("Java");
2. remove(Object obj)
Removes the specified element from the collection.
collection.remove("Java");
3. size()
Returns the total number of elements in the collection.
int count = collection.size();
4. isEmpty()
Checks whether the collection contains any elements.
collection.isEmpty();
5. clear()
Removes all elements from the collection.
collection.clear();
6. contains(Object obj)
Checks whether a specific element exists in the collection.
collection.contains("Java");
7. iterator()
Returns an Iterator for traversing collection elements.
Iterator<String> iterator =
collection.iterator();8. addAll(Collection c)
Adds all elements from another collection.
collection1.addAll(collection2);
9. removeAll(Collection c)
Removes all matching elements found in another collection.
collection1.removeAll(collection2);
10. retainAll(Collection c)
Keeps only the elements that are present in both collections.
collection1.retainAll(collection2);
11. containsAll(Collection c)
Checks whether all elements of another collection exist in the current collection.
collection1.containsAll(collection2);
12. toArray()
Converts the collection into an array.
Object[] array =
collection.toArray();The following example demonstrates some commonly used collection methods.
import java.util.ArrayList;
import java.util.Collection;
public class Demo {
public static void main(String[] args) {
Collection<String> skills =
new ArrayList<>();
skills.add("Java");
skills.add("Spring");
System.out.println(
"Size: " + skills.size());
System.out.println(
"Contains Java: "
+ skills.contains("Java"));
skills.remove("Spring");
System.out.println(skills);
System.out.println(
"Is Empty: "
+ skills.isEmpty());
}
}Size: 2
Contains Java: true
[Java]
Is Empty: false
A concise interview answer is
Some common methods available in the Collection interface are add(), remove(), size(), isEmpty(), clear(), contains(), iterator(), addAll(), removeAll(), retainAll(), containsAll(), and toArray(). These methods provide a consistent way to add, remove, search, and manage elements across different collection types.
Last updated: 16 July 2026
Previous question: Can you explain how Iterator works within the Java Collection Framework?
Next question: How does Java Collection Framework handle concurrency?