Set, List, or
Map. It was compiled for Java 1.4. Many additions have been made to the Collections Framework since then (notably the
Dequeinterfaces, and various items in
java.util.concurrent). These later additions have been omitted here, since this briefer summary should suffice for most cases.
The best general purpose or 'primary' implementations are likely
LinkedHashSet. Their overall performance is better, and you should use them
unless you need a special feature provided by another implementation. That
special feature is usually ordering or sorting.
For convenience, "ordering" will here refer to the order of items returned by an
and "sorting" will here refer to sorting items according to
||no duplicate keys||
Principal features of non-primary implementations:
HashMaphas slightly better performance than
LinkedHashMap, but its iteration order is undefined
HashSethas slightly better performance than
LinkedHashSet, but its iteration order is undefined
TreeSetis ordered and sorted, but slower
TreeMapis ordered and sorted, but slower
LinkedListhas fast adding to the start of the list, and fast deletion from the interior via iteration
LinkedHashSet- insertion order
LinkedHashMap- insertion order of keys (by default), or 'access order'
ArrayList- insertion order
LinkedList- insertion order
TreeSet- ascending order, according to
TreeMap- ascending order of keys, according to
LinkedHashMap, the re-insertion of an item does not affect insertion order.
LinkedHashMap, 'access order' is from the least recent access
to the most recent access. In this context, only calls to
putAll constitute an access, and only calls to these methods
affect access order.
While being used in a
Set, these items must
not change state (hence, it's recommended that these items be immutable
ResultSetas specified in an ORDER BY clause, insert the records into a