- Details
- Written by Nam Ha Minh
- Last Updated on 14 June 2019   |   Print Email
The following table summarizes the principal classes in Java collections framework for quick reference:
Main collection classes | D | O | S | TS |
ArrayList | Yes | Yes | No | No |
LinkedList | Yes | Yes | No | No |
Vector | Yes | Yes | No | Yes |
HashSet | No | No | No | No |
LinkedHashSet | No | Yes | No | No |
TreeSet | No | Yes | Yes | No |
HashMap | No | No | No | No |
LinkedHashMap | No | Yes | No | No |
Hashtable | No | No | No | Yes |
TreeMap | No | Yes | Yes | No |
- D: Duplicate elements is allowed?
- O: Elements are ordered?
- S: Elements are sorted?
- TS: The collection is thread-safe?
From this table we can conclude the following characteristics of the main collections in Java Collection Frameworks:
- All lists allow duplicate elements which are ordered by index.
- All sets and maps do not allow duplicate elements.
- All list elements are not sorted.
- Generally, sets and maps do not sort its elements, except TreeSet and TreeMap – which sort elements by natural order or by a comparator.
- Generally, elements within sets and maps are not ordered, except for:
- LinkedHashSet and LinkedHashMap have elements ordered by insertion order.
- TreeSet and TreeMap have elements ordered by natural order or by a comparator.
- There are only two collections are thread-safe: Vectorand Hastable. The rest is not thread-safe.
Java Collections Tutorials:
About the Author:
Nam Ha Minh is certified Java programmer (SCJP and SCWCD). He began programming with Java back in the days of Java 1.4 and has been passionate about it ever since. You can connect with him on
Facebook and watch
his Java videos on YouTube.