Phase X
The Collections Framework
Different ways to store data, and when each one makes sense.
Choose collection interfaces and implementations from their ordering, duplicate, lookup, insertion, and removal behaviour. Trace iteration, list costs, hashing, queues, heaps, and comparison rules using the object and generic type models from earlier phases.
When you finish this phase you can
- Explain why there is no single best data structure, using a concrete trade
- Read the framework hierarchy and say why Map sits outside Collection
- Explain how a for-each loop obtains and advances an iterator
- Choose between ArrayList and LinkedList from first principles, not folklore
- Explain how HashMap narrows a lookup to candidate entries
- Implement Comparable correctly and identify inconsistent comparison failures
- 10.1The Collections FrameworkChoose List, Set, Queue, or Map from the operations, ordering, duplicate, and lookup behaviour your program requires.The Collections Framework
- 10.2Iterable and the IteratorImplement and use Iterable and Iterator, trace how for-each obtains elements, and remove elements without corrupting traversal.Iterator
- 10.3The Collection InterfaceUse the core Collection operations, bulk methods, array conversion, and optional operations shared across collection types.Collection
- 10.4List: ArrayList, LinkedList, Vector, StackCompare ArrayList and LinkedList by operation cost, and recognise why the older Vector and Stack classes are usually replaced.List
- 10.5Set and Map: Inside HashMapUse Set and Map, trace a HashMap lookup through hashing and equality, and predict the effect of collisions and mutable keys.HashMapSet
- 10.6Map Operations and Specialized MapsUse Map update and lookup methods, then choose among HashMap, LinkedHashMap, TreeMap, EnumMap, IdentityHashMap, and WeakHashMap.EnumMap and EnumSet
- 10.7Queue, Deque, and PriorityQueueUse Queue and Deque operations, distinguish FIFO from priority ordering, and trace how PriorityQueue stores a binary heap in an array.Queue and DequeHeap
- 10.8Comparable, Comparator, and SortingDefine natural ordering with Comparable, supply alternative orderings with Comparator, and keep comparison consistent with equality where required.ComparableComparator