Skip to content
AITroveRead. Build. Understand.

Java Collections

Java collections supply membership, ordering and traversal contracts whose ownership, costs and concurrency behavior differ by implementation.

Java collections supply membership, ordering and traversal contracts whose ownership, costs and concurrency behavior differ by implementation.

Choose the question first

Use a List for ordered values, a Set for membership, a Map for a key-to-value association, or a Deque for endpoint work. Map is part of the collections framework but is not a subtype of Collection.

Ordering is a contract

TreeMap orders keys. LinkedHashMap keeps encounter order. PriorityQueue orders removals but does not supply sorted iteration. Those guarantees answer different questions.

Common Mistakes

Do not choose LinkedList simply because the workload inserts elements: finding an insertion position can dominate the edit. Count traversal, copying, allocation, and synchronisation needs before selecting an implementation.

Working through this section

The curriculum below groups the canonical pages for this section. Open a lesson to see its release label, operation contract and connected topics. Examples can also be linked from another section without creating a second copy of the same page.

Compile the stated program with a compatible JDK and compare its result with the displayed output. Read the rejected-input and ownership clauses before changing the input. Local self-checks and downloaded programs do not imply a server-side code judge or a production service.

Curriculum

Choose the operation family and keep mutation within a defined traversal policy.

  1. 1List, set or map?
  2. 2Java Iterator and ListIterator: traversal and controlled edits

Store mappings or unique values under a stable equality contract.

  1. 1Java HashMap: keys, collisions, and update operations
  2. 2Java HashSet: deduplication and equality

Inspect the state boundary and run its checked fixture.

  1. 1Java LinkedList ListIterator: edit at a cursor without repeated searches

Storage details