Junior — Middle
What is the main interface implemented by the Collection class in Java?
sobes.tech AI
Answer from AI
In Java, the Collection class is an interface that defines the core methods for working with groups of objects. It implements the Iterable interface, which allows using a for-each loop to iterate over elements.
The main methods of the Collection interface include:
add(E e)— add an element to the collectionremove(Object o)— remove an elementsize()— get the number of elementsisEmpty()— check if the collection is emptycontains(Object o)— check for the presence of an elementiterator()— get an iterator to traverse the elementsclear()— clear the collection
Thus, Collection serves as the base interface for all collections in Java, such as List, Set, and Queue, providing a unified contract for working with groups of objects.