Collections in Java

Serxan Hamzayev
JavaToDev
Published in
4 min readDec 21, 2022

--

In Java, the java.util.Collection interface represents a group of objects known as elements. The Collection interface is the root interface of the Java Collection Framework and provides the core methods that are used to manipulate a collection of objects.

The Java Collection Framework provides several implementations of the Collection interface, including the java.util.ArrayList, java.util.LinkedList, java.util.Vector, and java.util.Stack classes.

java.util.ArrayList is a class that implements the java.util.List interface and provides an implementation of a dynamic array. It is a resizable array, which means that it grows or shrinks automatically as elements are added or removed.

java.util.LinkedList is a class that implements the java.util.List interface and provides an implementation of a linked list. A linked list is a data structure that consists of a series of nodes, where each node contains a reference to the next node in the list.

Here is an example of how to create and use an ArrayList and a LinkedList in Java:

import java.util.ArrayList;
import java.util.LinkedList;

public class ListExample {

public static void main(String[] args) {

// Create an ArrayList
ArrayList<String> arrayList = new ArrayList<>();

// Add elements to the ArrayList
arrayList.add("element 1")…

--

--