ArrayLists, 2D arrays, inheritance, and recursion concepts tested on AP Computer Science A.
35 cards · basic cards · AI-written, checked twice. Edit anything.
- What is an ArrayList in Java?
Show answer
A resizable array that can grow or shrink dynamically at runtime
- How does an ArrayList differ from a regular array?
Show answer
ArrayList is resizable and part of the Collections Framework, while arrays have a fixed size set at creation
- What method adds an element to an ArrayList?
Show answer
add()
- What method removes an element from an ArrayList by index?
Show answer
remove()
- What method accesses an element in an ArrayList at a specific index?
Show answer
get()
- What import statement is required to use ArrayList?
Show answer
import java.util.ArrayList;
- What does the size() method return for an ArrayList?
Show answer
The number of elements currently in the ArrayList
- What exception is thrown when accessing an invalid ArrayList index?
Show answer
IndexOutOfBoundsException
- What is the time complexity of accessing an ArrayList element by index?
Show answer
O(1) - constant time
- What is a 2D array?
Show answer
An array of arrays, organized in rows and columns like a table or matrix
- How do you declare a 2D array of integers named matrix with 3 rows and 4 columns?
Show answer
int[][] matrix = new int[3][4];
- How do you access the element at row 1, column 2 in a 2D array?
Show answer
array[1][2]
- What does matrix.length return for a 2D array?
Show answer
The number of rows in the 2D array
- What does matrix[0].length return for a 2D array?
Show answer
The number of columns in the first row
- What is a ragged array?
Show answer
A 2D array where rows can have different numbers of columns