All java collections overview. Comparison is made by the following characteristics:
- Backed by — what data structure or collection is used under the hood
- Duplicates — whether duplicate values are allowed in collection
- Nulls allowed — whether collection allows inserting nulls
- Syncronized — are all methods of the collection syncronized or not
- Thread-safe — whether it’s safe to use this collection in a multi-threaded environment
- Iterator type — iterator behaviour in multi-threaded environment
Iterator types explained:
- 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
- snapshot-type — iterator saves a snapshot of a collection and iterates through it. Never throws ConcurrentModificationException.
- weakly consistent — may (but not guaranteed to) reflect some changes to the collection during the iteration. Don’t throw ConcurrentModificationException.