Java Tutorial · Revision notes
Java Collections Framework
The Collections Framework is a set of interfaces and classes in java.util that store and process groups of objects. This chapter covers the framework hierarchy, ArrayList, LinkedList, HashSet, TreeSet, HashMap and how to sort objects with Comparable and Comparator.
Quick revision
- Collection (List, Set, Queue) vs Map; Collections is a utility class
- ArrayList: array, 1.5× growth, fast get. LinkedList: nodes, fast ends, Deque
- HashSet unordered O(1); LinkedHashSet ordered; TreeSet sorted O(log n), no null
- HashMap: 16 buckets, 0.75 load, tree at 8, one null key
- Comparable inside class (compareTo); Comparator outside (compare)
- Use Iterator.remove() or removeIf to avoid ConcurrentModificationException