English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
In this tutorial, we will learn about the Java Collection interface and its sub-interfaces.
The Collection interface is the root interface of the Java collection framework.
This interface is not implemented directly. However, it is implemented through its sub-interfaces (such as List, Set, and Queue).
For example, the ArrayList class implements the List interface, which is a sub-interface of the Collection interface.
As described above, the Collection interface includes sub-interfaces implemented by various classes in Java.
The List interface is an ordered collection that allows us to add and delete elements like an array. For more information, please visitJava List Interface
The Set interface allows us to store elements in different collections, similar to sets in mathematics. It does not allow duplicate elements. For more information, please visitJava Set Interface
When we want toFirst In First Out (FIFO)When storing and accessing elements, the Queue interface can be used. For more information, please visitJava Queue Interface
The Collection interface includes various methods that can be used to perform different operations on objects. These methods are available in all of its sub-interfaces.
add() - Insert the specified element into the collection
size() - Return the size of the collection
remove() - Remove the specified element from the collection
iterator() - Return an iterator to access the elements of the collection
addAll() - Add all elements of the specified collection to the collection
removeAll() - Remove all elements of the specified collection from the collection
clear() - Remove all elements from the collection