Generics and collections

This part starts with the type parameter: the diamond, a bounded parameter, a generic method with ? extends and ? super, and type erasure, which is why new T[] is refused. The collections follow: List with ArrayList, the algorithms over it and the ConcurrentModificationException of a remove in a loop, Set in its three orders, Map with merge and entrySet, grouping and counting, Deque as a stack and as a queue, Comparable and Comparator, the Collections utilities, iteration with an iterator. A word index capstone closes it, next to the mutable key that disappears from a HashMap and the table that says which collection fits.

066 Generic classes a type parameter, the diamond, a bounded parameter, a generic pair Open 067 Generic methods and wildcards a generic method, ? extends, ? super, PECS, Collections.copy Open 068 Type erasure what the compiler erases, getClass on a list, why new T[] is refused, Class<T> Open 069 List and ArrayList add, get, set, remove, size, contains, ArrayList against LinkedList Open 070 Lists in practice Collections.sort, subList, an Iterator, ConcurrentModificationException Open 071 Set HashSet, LinkedHashSet, TreeSet, uniqueness, the order each keeps Open 072 Map put, get, getOrDefault, merge, keySet, values, entrySet Open 073 Grouping and counting computeIfAbsent, a map of lists, counting, sorting by value Open 074 Deque and ArrayDeque a stack, a queue, push and pop, offer and poll, peek Open 075 Comparable compareTo, natural order, a record that implements it, Arrays.sort Open 076 Comparator a lambda comparator, thenComparing, reversed, nullsLast, a sort by two keys Open 077 Collections and Arrays utilities unmodifiableList, emptyList, frequency, shuffle, max, asList and its limit Open 078 Iterating and removing for-each, Iterator.remove, ListIterator, the fail-fast check Open 079 Capstone: a word index a Map of lists, a sorted index, the output checked by hand Open 080 Keys, equals and hashCode a mutable key that disappears, a HashMap miss, the fix Open 081 Choosing a collection the cost table, when each of List, Set, Map and Deque fits Open

Lessons