Think of a container as a box for data: it groups multiple elements into one entity so programs can manage a collection conveniently. Arrays and linked lists are basic examples. section 7.6
Containers commonly support inserting, deleting, accessing, modifying, searching, and iterating over elements. They may preserve an order, such as insertion order, or follow rules defined by their type. section 7.8 section 7.13
A container describes shared behavior, while a data structure specifies organization in memory and operation complexity; an implementation turns that design into language-specific code. Different containers therefore trade off insertion, deletion, access, and search performance. section 7.13 section 7.8
Use the container’s rules and performance characteristics to choose an appropriate structure.
- Choose containers when data must be stored and processed as a collection, especially when an algorithm must traverse elements in a particular order. section 7.8
- Expect different containers to impose different rules for adding, accessing, or removing elements. section 7.8
- Do not classify every collection-oriented structure as a container: graphs emphasize relationships and connections, while k-d trees emphasize multidimensional organization and proximity queries. section 7.7
An Advent calendar
Representing 25 calendar days as separate variables makes the data awkward to manage. Placing them in an array treats the calendar as one organized container whose elements can be accessed by index. section 7.6
A box is the epitome of a container.
A box provides a simple mental model for a container: one entity holding multiple elements. section 7.6


