Layers of Logic

Phase X

The Collections Framework

Different ways to store data, and when each one makes sense.

8 sections152 min of reading34 exercises

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
  1. 10.1The Collections FrameworkChoose List, Set, Queue, or Map from the operations, ordering, duplicate, and lookup behaviour your program requires.The Collections FrameworkCore19 min4 exercises
  2. 10.2Iterable and the IteratorImplement and use Iterable and Iterator, trace how for-each obtains elements, and remove elements without corrupting traversal.IteratorCore18 min4 exercises
  3. 10.3The Collection InterfaceUse the core Collection operations, bulk methods, array conversion, and optional operations shared across collection types.CollectionCore16 min3 exercises
  4. 10.4List: ArrayList, LinkedList, Vector, StackCompare ArrayList and LinkedList by operation cost, and recognise why the older Vector and Stack classes are usually replaced.ListCore19 min4 exercises
  5. 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.HashMapSetDeeper24 min6 exercises
  6. 10.6Map Operations and Specialized MapsUse Map update and lookup methods, then choose among HashMap, LinkedHashMap, TreeMap, EnumMap, IdentityHashMap, and WeakHashMap.EnumMap and EnumSetCore18 min4 exercises
  7. 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 DequeHeapCore18 min3 exercises
  8. 10.8Comparable, Comparator, and SortingDefine natural ordering with Comparable, supply alternative orderings with Comparator, and keep comparison consistent with equality where required.ComparableComparatorCore20 min6 exercises