Java List Interface: Overview, Implementations, and Key Methods
Java List Interface
Explore the Java List interface—its purpose, common implementations, essential methods, and how it differs from Set.
In Java, the List interface represents an ordered, index‑based collection that supports duplicates and random access. It extends Collection and is part of the Collections Framework.
Key Implementations of List
Because List is an interface, you instantiate concrete classes to use its functionality:
- ArrayList – backed by a dynamic array, offers fast random access.
- LinkedList – implemented as a doubly‑linked list, excels at insertions/deletions.
- Vector – legacy synchronized list, rarely used in modern code.
- Stack – a subclass of Vector that follows LIFO semantics.

These classes are defined within the java.util package.
Using List in Code
First import java.util.List (and the concrete class you wish to use).
// ArrayList implementation
List<String> arrayList = new ArrayList<>();
// LinkedList implementation
List<String> linkedList = new LinkedList<>();
The variables arrayList and linkedList now expose all List methods.
Essential List Methods
All methods listed below are inherited from Collection and are available on every List implementation.
add(E e)– append an element.addAll(Collection<? extends E> c)– bulk addition.get(int index)– retrieve by index.iterator()– sequential traversal.set(int index, E element)– replace element.remove(Object o)– delete by value.removeAll(Collection<? extends E> c)– bulk removal.clear()– empty the list.size()– number of elements.toArray()– convert to array.contains(Object o)– test membership.
ArrayList in Practice
import java.util.List;
import java.util.ArrayList;
public class ArrayListDemo {
public static void main(String[] args) {
List<Integer> numbers = new ArrayList<>();
numbers.add(1);
numbers.add(2);
numbers.add(3);
System.out.println("List: " + numbers);
int third = numbers.get(2);
System.out.println("Accessed Element: " + third);
int removed = numbers.remove(1);
System.out.println("Removed Element: " + removed);
}
}
Output
List: [1, 2, 3] Accessed Element: 3 Removed Element: 2
For deeper insight into ArrayList, consult the official Oracle documentation.
LinkedList in Practice
import java.util.List;
import java.util.LinkedList;
public class LinkedListDemo {
public static void main(String[] args) {
List<Integer> numbers = new LinkedList<>();
numbers.add(1);
numbers.add(2);
numbers.add(3);
System.out.println("List: " + numbers);
int third = numbers.get(2);
System.out.println("Accessed Element: " + third);
int index = numbers.indexOf(2);
System.out.println("Position of 2 is " + index);
int removed = numbers.remove(1);
System.out.println("Removed Element: " + removed);
}
}
Output
List: [1, 2, 3] Accessed Element: 3 Position of 2 is 1 Removed Element: 2
Further details on LinkedList are available in the Java Tutorials.
List vs. Set
Both interfaces extend Collection but differ in key aspects:
- Lists preserve insertion order and allow duplicates.
- Sets enforce uniqueness and typically have no defined order (unless a
SortedSetis used).
Choosing between them depends on whether order and duplicates matter for your use case.
Continue exploring concrete implementations in upcoming tutorials.
Java
- Java TreeMap: Master Sorted Maps with Practical Examples
- Mastering Java ConcurrentHashMap: Operations, Examples, and Best Practices
- Java HashSet Class: Complete Guide to Operations, Methods, and Set Theory
- Mastering Java TreeSet: Operations, Methods, and Practical Examples
- Mastering Java Collection Algorithms: Sorting, Shuffling, and More
- Master Java Autoboxing and Unboxing: Practical Examples and Best Practices
- Generate Random Numbers in Java: Practical Guide with Random and Math.random
- Java Numbers Class – Wrapper Classes & Inheritance Explained
- Java 10: 70+ New APIs & Features Explained
- Java 9 Collection Factory Methods: Simplify Immutable List, Set & Map Creation