Card 08/ 08
Recap: Arrays
Fixed at creation, filled with defaults, indexed from zero, and never able to grow, with where each was.
Arrays come down to the five ideas below, each listed with the card that covers it.
| The idea | Where |
|---|---|
| One variable, a fixed length, one element type, all decided at creation | Java Arrays: A Fixed Number of Values Under One Name |
| Declare, allocate, fill; every slot starts at its type's default | Creating an Array: Declare, Allocate and Fill |
The index is an offset, so the last one is length - 1 | Zero-Based Indexes Example: Why the Last of Seven Is Index 6 |
array.length, string.length(), collection.size() | length vs length() vs size() |
Arrays never grow; Arrays.copyOf makes a new one and copies | Why a Java Array Cannot Grow |
An array is a fixed run of slots, and every surprise in this topic comes from that one fact: the offset, the exception, and the copy you have to make to add anything.
← → move through sections and cards