1/11
Flashcards for Java Arrays and ArrayLists
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai | Chat |
|---|
No analytics yet
Send a link to your students to track their progress
Array
A data structure in Java that can hold a fixed number of elements of the same type.
ArrayList
A dynamic list in Java that allows adding and removing elements, providing flexibility in size.
Static (Array)
Arrays are static, meaning their length cannot be changed once created.
Dynamic (ArrayList)
ArrayLists are dynamic, meaning they can grow or shrink to accommodate more or fewer elements.
Generics
ArrayList support Generics, hence they provide compile time type-safety.
Primitives and Objects (Array)
Arrays can hold both primitive types (int, char) and objects (String, Integer).
Objects (ArrayList)
ArrayLists can only hold object elements; they cannot store primitive types directly.
Memory Usage (Array vs. ArrayList)
Arrays typically take less memory than ArrayLists for storing the same number of elements.
Element Removal
ArrayList allows you to remove element, but array doesn't provide such methods.
Multi-dimensionality
Arrays can be multi-dimensional, while ArrayLists are always one-dimensional.
Length vs Size
Array length attribute is capacity, whereas ArrayList size() method returns the number of elements.