Unit 4 Data Collections in AP Computer Science A (Java): Arrays, ArrayLists, and 2D Arrays

0.0(0)
Studied by 0 people
0%Unit 4 Mastery
0%Exam Mastery
Build your Mastery score
multiple choiceMultiple Choice
call kaiCall Kai
Supplemental Materials
Card Sorting

1/52

Last updated 3:08 PM on 3/12/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

53 Terms

1
New cards

Data collection

A structure that stores many values and lets you work with them as a group (e.g., arrays, ArrayLists, 2D arrays).

2
New cards

Index-based access

Referring to collection elements by position (0, 1, 2, …) to read or update values.

3
New cards

Array

A fixed-size, indexed object that stores elements of the same type.

4
New cards

ArrayList

A resizable, indexed list from the Java Collections Framework that can grow/shrink as elements are added/removed.

5
New cards

2D array

An array whose elements are arrays; used to model grids/tables (rows and columns).

6
New cards

Reference

A value that points to an object’s location; collection variables store references, not the entire object.

7
New cards

Object (in context of collections)

A heap-allocated entity in Java; arrays, ArrayLists, and 2D arrays are objects and are referenced by variables.

8
New cards

Aliasing

When two variables refer to the same object, so changes through one variable are visible through the other.

9
New cards

Side effect (collections)

A method call that changes the original array/ArrayList passed in (because the reference points to the same object).

10
New cards

Fixed size

Array property: once created, an array’s length cannot change.

11
New cards

0-based indexing

Indexing system where the first element is at index 0 and the last is at index length-1 (or size-1).

12
New cards

Homogeneous type

Array rule: all elements in an array must be the same declared type (e.g., int[] only holds int).

13
New cards

Array initializer

Syntax that creates and fills an array at once, e.g., int[] a = {90, 85, 100};

14
New cards

Default values (arrays)

Values automatically stored in a newly created array: 0 (int), 0.0 (double), false (boolean), null (reference types).

15
New cards

null

The default value for reference types; indicates “no object reference.”

16
New cards

ArrayIndexOutOfBoundsException

Runtime error thrown when accessing an array with an invalid index (

17
New cards

length (array field)

Array property that gives the number of elements; used as arr.length (no parentheses).

18
New cards

size() (ArrayList method)

Returns the current number of elements in an ArrayList.

19
New cards

Off-by-one error

A boundary mistake in indexing/loop bounds, such as using i <= arr.length instead of i < arr.length.

20
New cards

Traversal

Systematically visiting elements of a collection to compute a result or modify the collection.

21
New cards

Index-based for loop (arrays)

Common traversal pattern: for (int i = 0; i < arr.length; i++) { … }

22
New cards

Enhanced for loop (for-each)

Traversal that iterates over values directly (no explicit index), e.g., for (int x : arr) { … }

23
New cards

For-each variable is a copy (primitives)

In a for-each loop over primitives, the loop variable holds a copy; changing it does not change the array element.

24
New cards

Accumulator

A variable (like sum) initialized before a loop and updated each iteration to combine values.

25
New cards

Accumulation (sum/total) algorithm

Traversal pattern that adds each element into an accumulator to compute a total (and often an average).

26
New cards

Integer division pitfall

When dividing ints in Java, the result is truncated; use double if you need a decimal average.

27
New cards

Maximum/minimum algorithm

Pattern that tracks a “best so far” value, typically initialized to the first element and updated via comparisons.

28
New cards

Counting with a condition

Traversal pattern that increments a counter when elements satisfy a boolean test (e.g., count values equal to 10).

29
New cards

In-place replacement (map/transform)

Algorithm that overwrites each element using its old value, e.g., arr[i] = arr[i] * arr[i].

30
New cards

Shifting (array removal idea)

Moving elements left/right to simulate insertion/removal in an array since its length can’t change.

31
New cards

Logical size

A separate variable used with arrays to track how many positions are currently “valid” after shifting/removal-like operations.

32
New cards

Resizable

ArrayList property: it can automatically grow or shrink as elements are added or removed.

33
New cards

Wrapper class

An object type that represents a primitive for use in collections (e.g., Integer for int, Double for double).

34
New cards

Autoboxing/unboxing

Java automatically converts between primitives and wrapper objects when needed (e.g., int ↔ Integer).

35
New cards

get(i) (ArrayList)

Returns the element at index i in an ArrayList.

36
New cards

set(i, value) (ArrayList)

Replaces the element at index i and returns the old element.

37
New cards

add(value) (ArrayList)

Appends an element to the end of an ArrayList.

38
New cards

add(i, value) (ArrayList)

Inserts an element at index i and shifts later elements to the right.

39
New cards

remove(i) (ArrayList)

Removes the element at index i, shifts later elements left, and returns the removed element.

40
New cards

Shifting behavior (ArrayList)

After insertion/removal at an index, later elements move to keep indices contiguous.

41
New cards

Concurrent modification (enhanced for loop)

Adding/removing elements from an ArrayList during an enhanced for loop is not allowed and typically causes a runtime error.

42
New cards

Backward traversal for removals

Looping from size()-1 down to 0 to safely remove elements without skipping due to shifting.

43
New cards

remove(int) vs remove(Object) (ArrayList)

For ArrayList, remove(10) is treated as “remove index 10”; to remove the value 10 use remove(Integer.valueOf(10)).

44
New cards

== vs .equals() (objects)

== checks if two references are the same object; .equals() checks logical/content equality (commonly needed in collections).

45
New cards

Linear search

Searching by checking each element in order until a match is found or the end is reached.

46
New cards

Sentinel value (-1)

A special return value often used to indicate “not found” in search methods.

47
New cards

Collections.sort

Library method that sorts an ArrayList in place according to natural ordering (e.g., Strings alphabetically).

48
New cards

Arrays.sort

Library method that sorts an array in place (e.g., int[] in ascending order).

49
New cards

In-place sort side effect

Sorting rearranges the same collection object; the original order is lost unless you copied it first.

50
New cards

Ragged array

A 2D array where rows can have different lengths because each row is a separate array.

51
New cards

Row-major order

2D traversal that visits all columns of row 0, then row 1, and so on (nested loops over rows then columns).

52
New cards

2D array length rules

grid.length is the number of rows; grid[r].length is the number of columns in row r.

53
New cards

Bounds check (neighbors in a grid)

Verifying indices are valid before accessing adjacent cells (e.g., ensure c+1 < grid[r].length before using grid[r][c+1]).

Explore top notes

note
Ch 30 - Barriers to Development
Updated 1071d ago
0.0(0)
note
Social Learning Theory
Updated 415d ago
0.0(0)
note
Nervous System Part 1
Updated 392d ago
0.0(0)
note
AP PSYCH 2.9 Sleep and Dreaming
Updated 1062d ago
0.0(0)
note
DNA Repair
Updated 1310d ago
0.0(0)
note
Chapter 9 Agriculture Topics
Updated 1115d ago
0.0(0)
note
Ch 30 - Barriers to Development
Updated 1071d ago
0.0(0)
note
Social Learning Theory
Updated 415d ago
0.0(0)
note
Nervous System Part 1
Updated 392d ago
0.0(0)
note
AP PSYCH 2.9 Sleep and Dreaming
Updated 1062d ago
0.0(0)
note
DNA Repair
Updated 1310d ago
0.0(0)
note
Chapter 9 Agriculture Topics
Updated 1115d ago
0.0(0)

Explore top flashcards

flashcards
Cell Organelles
21
Updated 377d ago
0.0(0)
flashcards
Midterm Vocabulary - Bio 20 AP
143
Updated 282d ago
0.0(0)
flashcards
Harrison History Chapter 3
58
Updated 539d ago
0.0(0)
flashcards
Sport, Spiel, und Spaß
60
Updated 189d ago
0.0(0)
flashcards
MAME Final
197
Updated 469d ago
0.0(0)
flashcards
Tejido nervioso
58
Updated 1002d ago
0.0(0)
flashcards
Cell Organelles
21
Updated 377d ago
0.0(0)
flashcards
Midterm Vocabulary - Bio 20 AP
143
Updated 282d ago
0.0(0)
flashcards
Harrison History Chapter 3
58
Updated 539d ago
0.0(0)
flashcards
Sport, Spiel, und Spaß
60
Updated 189d ago
0.0(0)
flashcards
MAME Final
197
Updated 469d ago
0.0(0)
flashcards
Tejido nervioso
58
Updated 1002d ago
0.0(0)