Back to blog
January 9, 20266 min readMarina

Java Collections in Real Systems | Part 2: List

JavaCollectionsList

Java Collections in Real Systems | Part 2: List

List in Java Collections

If Set is about uniqueness, List is about order and position.

Duplicates are allowed and index-based access becomes part of the contract.

List

  • Ordered collection
  • Allows duplicate elements
  • Access by index
  • ArrayList

  • Fast random access
  • Ideal for read-heavy scenarios
  • Use case: transaction history
  • List<String> transactions = new ArrayList<>();
    transactions.add("TX1001");
    transactions.add("TX1002");
    transactions.add("TX1003");
    transactions.add("TX1002"); // duplicate allowed

    LinkedList

  • Fast insertions and removals
  • Slower index access
  • Use case: processing steps in a workflow
  • List<String> workflowSteps = new LinkedList<>();
    workflowSteps.add("VALIDATE");
    workflowSteps.add("AUTHORIZE");
    workflowSteps.add("SETTLE");
    workflowSteps.add("AUTHORIZE"); // duplicate allowed

    Think

  • Use List when order is meaningful
  • ArrayList → fast reads and index access
  • LinkedList → frequent insertions and removals
  • If you want the big-picture comparison between List, Set, and Map, read the intro:

    List, Set, and Map: Key Differences in Java Collections.

    Previous in the series:

    Java Collections in Real Systems | Part 1: Set.

    Next in the series:

    Java Collections in Real Systems | Part 3: Map.