Java Collections Framework summary table
- 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:
- What is Java Collections Framework?
- Java List Tutorial
- Java Set Tutorial
- Java Map Tutorial
- Java Queue Tutorial
- Understanding Collections and Thread Safety in Java
- Understanding equals and hashCode in Java
- 18 Java Collections and Generics Best Practices
- Understanding Object Ordering in Java
Comments
Ordered are insertion order preserved and it may not be same as sorted.
Ordered means it will maintain the insertions order. So you will get the same value every time. Sorted means elements will be sorted on ascending order A to Z
they why we have separate columns.