English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Java Basic Tutorial

Java Flow Control

Java Array

Java Object-Oriented (I)

Java Object-Oriented (II)

Java Object-Oriented (III)

Java Exception Handling

Java List (List)

Java Queue (Queue)

Java Map Collection

Java Set Collection

Java Input Output (I/O)

Java Reader/Writer

Java Other Topics

Java Collection Interfaces (Collection)

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.

Sub-interfaces of Collection

As described above, the Collection interface includes sub-interfaces implemented by various classes in Java.

1.List interface

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

2.Set 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

3.Queue 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

Collection Methods

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