List is an ordered collection that:

  • allows duplicates,
  • maintains insertion order,
  • supports index-based access.

It extends the Collection interface.

Common Implementations

ImplementationFeatures
ArrayListFast reads, resizable array, slow inserts/removes
LinkedListFast inserts/removes, slower random access
VectorLike ArrayList but synchronized (legacy)
StackLIFO (extends Vector)

Example

List<String> names = new ArrayList<>();
names.add("Kamil");
names.add("Kamil"); // duplicates allowed
System.out.println(names.get(0)); // Kamil

Methods

list.add("A");
list.get(0);
list.set(0, "B");
list.remove(0);
list.contains("B");
list.size();
list.clear();

Comparison

ArrayList vs LinkedList

FeatureArrayListLinkedList
Backed ByDynamic arrayDoubly-linked list
Access TimeFast (O(1))Slower (O(n)
Insert/DeleteSlower (Shifts)Faster (O(1) if at ends)
MemoryCompactMore (due to nodes)

Use Cases

  • ArrayList: fast access, read-heady apps.
  • LinkedList: frequent insert/delete (e.g. queues).
  • Vector: thread-safe legacy code (avoid unless needed).
  • Stack: LIFO operations (use Deque instead in modern code).

Tip

Be ready to explain:

  • compare ArrayList vs LinkedList,
  • show time complexity awareness,
  • explain why List allows duplicates and index access.

Parent: _Collections