List Interface in Java
👉 List is an interface in Java Collections Framework that represents an ordered collection of elements (sequence) where duplicates are allowed.
Key Characteristics of List
✔ Ordered collection (insertion order preserved)
✔ Allows duplicates
✔ Index-based access (like array)
✔ Part of java.util package
✔ Extends Collection interface
Static Methods in List Interface:
List interface has static methods, introduced in Java 8 (and expanded in Java 9).
Static methods in List
✔ 1. List.of() (Java 9+)
List<String> list = List.of("A", "B", "C");
👉 Creates an immutable list
No add/remove allowed
No null values allowed
Very fast and memory efficient
These static methods are utility/factory methods that belong to the interface itself, not to objects
✔ 2. List.copyOf() (Java 10+)
List<String> copy = List.copyOf(existingList);
👉 Creates an immutable copy of an existing list
Behavior:
If source is already immutable → returns same reference
Otherwise → creates new immutable list
Types of List Implementations
1. ArrayList
Fast random access
Slower insert/delete in middle
2. LinkedList
Fast insert/delete
Slower access
3. Vector
Synchronized (thread-safe)
Legacy class
4. Stack
Follows LIFO (Last In First Out)

Top comments (0)