As far as best practices go, you shouldn't worry about performance, but about using the collection that conceptually fits your design. Duplicates are allowed, or elements have a position? Use a
List. Elements are unique, and you don't don't care about their position? Use a
Set. Elements need to remain sorted? Use a
SortedSet. Elements need to go in on one side and come out of the other? Use a
Queue. Elements need to be stacked? Use a
Deque.
There's no point in comparing an
ArrayList to a
HashSet, because they perform different jobs. You can compare a
LinkedList to an
ArrayList, or a
HashSet to a
TreeSet, but only after you've decided whether you need a
List or a
Set.
There is usually an implementation for each interface that
you should use first, and only change if you have good reasons to believe your application requires another implementation. These are:
Interface | Goto implementation |
---|
List | ArrayList |
Set | LinkedHashSet or EnumSet |
SortedSet | TreeSet |
Queue or Deque | ArrayDeque |
Map | LinkedHashMap or EnumMap |
SortedMap | TreeMap |