1/9
Prelim Topic
Name | Mastery | Learn | Test | Matching | Spaced |
|---|
No study sessions yet.
ArrayList
A class within the java.util package
Provides dynamic-sized arrays in Java
Part of Java’s Collections Framework
It automatically adjusts its capacity as elements are added or removed.
Class Hierarchy and Interfaces
(Characteristics of ArrayList)
ArrayList inherits from AbstractList class
ArrayList implements the List interface
This means it adheres to the List contract, providing common list operations
Dynamic Sizing and Capacity Management
(Characteristics of ArrayList)
ArrayList is initialized with a size (or default capacity)
Its size can increase automatically as the collection grows
It can shrink automatically if objects are removed
Random Access Capability
(Characteristics of ArrayList)
Java ArrayList allows for random access to elements
This means you can efficiently retrieve an element directly by its index ( e.g., get(index)).
Handling Primitive Types
(Characteristics of ArrayList)
ArrayList cannot directly store primitive types (int, char, boolean, double, etc.)
You must use wrapper classes (e.g, Integer for int, Character for char) when adding primitives to an ArrayList
Example: ArrayList<integer> numbers = new ArrayList<>();
C++ Vector Analogy
(Characteristics of ArrayList)
ArrayList in Java can be seen as similar to a vector C++
Both provide dynamic array functionality, allowing elements to be added or removed while managing underlying memory