Fiveable
Fiveable

Initial capacity

Definition

Initial capacity refers to the starting size or capacity allocated for an ArrayList when it is created using its constructor. It determines how many elements can be stored in the list before it needs to dynamically resize itself.

Analogy

Imagine you are going on a road trip and need to pack your car trunk. The initial capacity is like having a certain amount of space available in your trunk at first. If you have a larger initial capacity, you can fit more items without needing to make additional trips back home.

Related terms

resize(): This operation increases or decreases the size/capacity of an array-based data structure like an ArrayList.

ensureCapacity(): This method ensures that an ArrayList has enough space allocated for a specified number of elements without needing frequent resizing.

trimToSize(): This method reduces the capacity of an ArrayList to match its current size, freeing up any excess memory.

"Initial capacity" appears in:

collegeable - rocket pep

Are you a college student?

  • Study guides for the entire semester

  • 200k practice questions

  • Glossary of 50k key terms - memorize important vocab



© 2024 Fiveable Inc. All rights reserved.

AP® and SAT® are trademarks registered by the College Board, which is not affiliated with, and does not endorse this website.


© 2024 Fiveable Inc. All rights reserved.

AP® and SAT® are trademarks registered by the College Board, which is not affiliated with, and does not endorse this website.