Java collections cheat sheet

Danila Varatyntsev
1 min readJun 6, 2021

--

All java collections overview. Comparison is made by the following characteristics:

  1. Backed by — what data structure or collection is used under the hood
  2. Duplicates — whether duplicate values are allowed in collection
  3. Nulls allowed — whether collection allows inserting nulls
  4. Syncronized — are all methods of the collection syncronized or not
  5. Thread-safe — whether it’s safe to use this collection in a multi-threaded environment
  6. Iterator type — iterator behaviour in multi-threaded environment
Java collections overview

Iterator types explained:

  1. fail-fast — iterator saves a collection’s “generation number” on creation, which is basically the number of changed made to collection. During the iteration it compares current generation with saved. If they are different, a ConcurrentModificationException is thrown
  2. snapshot-type — iterator saves a snapshot of a collection and iterates through it. Never throws ConcurrentModificationException.
  3. weakly consistent — may (but not guaranteed to) reflect some changes to the collection during the iteration. Don’t throw ConcurrentModificationException.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

No responses yet

Write a response