---
title: "Chapter 18: Common Collections"
description: "The 9 lessons of chapter 18: Common Collections, in teaching order."
url: "https://learnrust.net/chapter-18/"
last_updated: "2026-06-13"
---

# Chapter 18: Common Collections

- [18.1 Introduction to collections](https://learnrust.net/chapter-18/introduction-to-collections.md): What the standard collections are, why they live on the heap and can grow at runtime, and a map of Vec, String, and HashMap before diving in.
- [18.2 Vec: creating and updating](https://learnrust.net/chapter-18/vec-creating-and-updating.md): Creating vectors with Vec::new and the vec! macro, pushing and popping, and the crucial difference between get (returns Option) and [] indexing (panics out of bounds).
- [18.3 Vec: iterating and borrowing](https://learnrust.net/chapter-18/vec-iterating-and-borrowing.md): Iterating a vector by shared reference, mutable reference, and by value, and why the borrow checker forbids modifying a vector while iterating over it.
- [18.4 Vec: capacity and growth](https://learnrust.net/chapter-18/vec-capacity-and-growth.md): The difference between a vector's length and its capacity, how pushing triggers reallocation, and using with_capacity to avoid repeated reallocations.
- [18.5 String as a collection](https://learnrust.net/chapter-18/string-as-a-collection.md): String is a UTF-8 byte buffer: why s[0] doesn't compile, the difference between chars() and bytes(), and why slicing a string can panic.
- [18.6 HashMap](https://learnrust.net/chapter-18/hashmap.md): Storing key-value pairs in a HashMap: insert and get, the entry API for update-or-insert, and how ownership works for keys and values.
- [18.7 Arrays and slices, revisited](https://learnrust.net/chapter-18/arrays-and-slices-revisited.md): Fixed-size arrays [T; N] in depth, when a fixed length wins, slices as the universal parameter type that accepts arrays and vectors alike, and nested data for 2D grids.
- [18.8 Choosing a collection](https://learnrust.net/chapter-18/choosing-a-collection.md): A decision guide to the standard collections: when VecDeque, HashSet, and BTreeMap beat the core three, with a quick comparison table.
- [18.x Chapter 18 summary and quiz](https://learnrust.net/chapter-18/chapter-18-summary-and-quiz.md): Review of Vec, String as UTF-8, HashMap, arrays and slices, and choosing a collection, with a chapter quiz and a capstone program.

## Sitemap

See the full [sitemap](https://learnrust.net/sitemap.md) for all pages.
