Unit 4 Data Collections Practice Exam - 50 Questions | AP CSA 2025-26

Unit 4: Data Collections

50 Questions • AP Exam Difficulty • New 4-Unit Curriculum (2025-26)

1D Arrays • ArrayList • 2D Arrays • Traversals & Algorithms

0 Correct | 0 Incorrect | 0/50 Answered
1D Array Basics & Traversals (Questions 1-14)
Question 1

What is printed?

int[] arr = new int[5]; System.out.println(arr[0]);
Question 2

What is printed?

int[] arr = {10, 20, 30, 40, 50}; System.out.println(arr[arr.length - 1]);
Question 3

What is printed?

int[] arr = {1, 2, 3, 4, 5}; System.out.println(arr[5]);
Question 4

What is printed?

int[] arr = {2, 4, 6, 8, 10}; int sum = 0; for (int i = 0; i < arr.length; i++) { sum += arr[i]; } System.out.println(sum);
Question 5

What is printed?

int[] arr = {5, 10, 15, 20}; for (int val : arr) { System.out.print(val + " "); }
Question 6

What is printed?

int[] arr = {3, 7, 2, 9, 4}; int max = arr[0]; for (int i = 1; i < arr.length; i++) { if (arr[i] > max) { max = arr[i]; } } System.out.println(max);
Question 7

What is printed?

int[] arr = {1, 2, 3, 4, 5}; for (int i = 0; i < arr.length; i++) { arr[i] = arr[i] * 2; } System.out.println(arr[2]);
Question 8

What is printed?

int[] arr = {1, 2, 3, 4, 5}; for (int val : arr) { val = val * 2; } System.out.println(arr[2]);
Question 9

What is printed?

int[] a = {1, 2, 3}; int[] b = a; b[0] = 99; System.out.println(a[0]);
Question 10

What is printed?

int[] arr = {10, 20, 30, 40, 50}; int count = 0; for (int val : arr) { if (val > 25) { count++; } } System.out.println(count);
Question 11

What is printed?

String[] names = new String[3]; System.out.println(names[0]);
Question 12

What is printed?

int[] arr = {5, 3, 8, 1, 9, 2}; int minIndex = 0; for (int i = 1; i < arr.length; i++) { if (arr[i] < arr[minIndex]) { minIndex = i; } } System.out.println(minIndex);
Question 13

What is printed?

int[] arr = {1, 2, 3, 4, 5}; for (int i = arr.length - 1; i >= 0; i--) { System.out.print(arr[i] + " "); }
Question 14

What does this method return for arr = {2, 4, 6, 8}?

public static boolean allEven(int[] arr) { for (int val : arr) { if (val % 2 != 0) { return false; } } return true; }
ArrayList (Questions 15-28)
Question 15

Which correctly declares an ArrayList of Strings?

Question 16

What is printed?

ArrayList list = new ArrayList(); list.add(10); list.add(20); list.add(30); System.out.println(list.size());
Question 17

What is printed?

ArrayList list = new ArrayList(); list.add("A"); list.add("B"); list.add("C"); System.out.println(list.get(1));
Question 18

What is printed?

ArrayList list = new ArrayList(); list.add(5); list.add(10); list.add(15); list.set(1, 99); System.out.println(list.get(1));
Question 19

What is printed?

ArrayList list = new ArrayList(); list.add("X"); list.add("Y"); list.add("Z"); list.remove(1); System.out.println(list);
Question 20

What is printed?

ArrayList list = new ArrayList(); list.add(1); list.add(2); list.add(0, 99); System.out.println(list);
Question 21

What is the problem with this code?

ArrayList list = new ArrayList(); list.add(1); list.add(2); list.add(3); for (int i = 0; i < list.size(); i++) { list.remove(i); } System.out.println(list);
Question 22

Which correctly removes all even numbers?

ArrayList list = new ArrayList(); // list contains [2, 5, 8, 3, 6]
Question 23

What is printed?

ArrayList list = new ArrayList(); list.add(10); list.add(20); list.add(30); for (int val : list) { System.out.print(val + " "); }
Question 24

What is the main difference between arrays and ArrayLists?

Question 25

What is printed?

ArrayList list = new ArrayList(); list.add("cat"); list.add("dog"); list.add("bird"); System.out.println(list.indexOf("dog"));
Question 26

What is printed?

ArrayList nums = new ArrayList(); nums.add(5); nums.add(10); nums.add(15); int sum = 0; for (int i = 0; i < nums.size(); i++) { sum += nums.get(i); } System.out.println(sum);
Question 27

What wrapper class is used for int in ArrayList?

Question 28

What is printed?

ArrayList list = new ArrayList(); list.add("A"); list.add("B"); String removed = list.remove(0); System.out.println(removed + " " + list.size());
2D Arrays (Questions 29-42)
Question 29

What is printed?

int[][] arr = new int[3][4]; System.out.println(arr.length + " " + arr[0].length);
Question 30

What is printed?

int[][] arr = {{1, 2, 3}, {4, 5, 6}}; System.out.println(arr[1][2]);
Question 31

How many total elements are in this ragged array?

int[][] arr = {{1, 2}, {3, 4, 5}, {6}};
Question 32

What is printed?

int[][] grid = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; int sum = 0; for (int row = 0; row < grid.length; row++) { for (int col = 0; col < grid[row].length; col++) { sum += grid[row][col]; } } System.out.println(sum);
Question 33

What is printed?

int[][] arr = {{1, 2, 3}, {4, 5, 6}}; for (int[] row : arr) { for (int val : row) { System.out.print(val + " "); } }
Question 34

What traversal order does this code use?

for (int col = 0; col < arr[0].length; col++) { for (int row = 0; row < arr.length; row++) { System.out.print(arr[row][col] + " "); } }
Question 35

What is printed? (Main diagonal sum)

int[][] arr = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; int sum = 0; for (int i = 0; i < arr.length; i++) { sum += arr[i][i]; } System.out.println(sum);
Question 36

What is printed? (Aliasing in 2D arrays)

int[][] arr = {{1, 2, 3}, {4, 5, 6}}; arr[0] = arr[1]; arr[1][0] = 99; System.out.println(arr[0][0]);
Question 37

What is printed?

int[][] grid = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; int count = 0; for (int[] row : grid) { for (int val : row) { if (val % 2 == 0) { count++; } } } System.out.println(count);
Question 38

What is printed?

String[][] words = {{"A", "B"}, {"C", "D", "E"}}; System.out.println(words[1].length);
Question 39

What is printed?

int[][] matrix = {{1, 2}, {3, 4}}; for (int r = 0; r < matrix.length; r++) { for (int c = 0; c < matrix[r].length; c++) { if (r == c) { matrix[r][c] *= 2; } } } System.out.println(matrix[0][0] + matrix[1][1]);
Question 40

What is printed?

int[][] arr = new int[2][3]; System.out.println(arr[1][2]);
Question 41

What does this code compute?

int[][] grid = {{1, 2, 3}, {4, 5, 6}}; int result = 0; for (int c = 0; c < grid[0].length; c++) { result += grid[0][c]; } System.out.println(result);
Question 42

What does this code compute?

int[][] grid = {{1, 2, 3}, {4, 5, 6}}; int result = 0; for (int r = 0; r < grid.length; r++) { result += grid[r][0]; } System.out.println(result);
Mixed Applications & Algorithms (Questions 43-50)
Question 43

What is printed? (Linear search)

int[] arr = {5, 3, 8, 1, 9}; int target = 8; int index = -1; for (int i = 0; i < arr.length; i++) { if (arr[i] == target) { index = i; break; } } System.out.println(index);
Question 44

What is printed?

ArrayList list = new ArrayList(); list.add(10); list.add(20); list.add(30); list.add(1, 15); System.out.println(list.get(2));
Question 45

What is printed?

int[] arr = {1, 2, 3, 4, 5}; int[] copy = arr; copy[0] = 100; System.out.println(arr[0] + " " + copy[0]);
Question 46

What is printed?

int[][] arr = {{1, 2}, {3, 4}, {5, 6}}; int sum = 0; for (int r = 0; r < arr.length; r++) { sum += arr[r][arr[r].length - 1]; } System.out.println(sum);
Question 47

What is printed?

ArrayList list = new ArrayList(); list.add("A"); list.add("B"); list.add("C"); list.add("B"); list.remove("B"); System.out.println(list);
Question 48

What is printed?

int[] arr = {4, 2, 7, 1, 5}; double avg = 0; for (int val : arr) { avg += val; } avg = avg / arr.length; System.out.println(avg);
Question 49

What is printed?

int[][] grid = {{1, 2, 3}, {4, 5, 6}}; int max = grid[0][0]; for (int[] row : grid) { for (int val : row) { if (val > max) { max = val; } } } System.out.println(max);
Question 50

Which is true about arrays and ArrayLists?

🎉 Unit 4: Data Collections Complete!

Review your answers above or click Reset to practice again.

New 4-Unit AP CSA Curriculum (2025-26) • APCSExamPrep.com

Get in Touch

Whether you're a student, parent, or teacher — I'd love to hear from you.

Just want free AP CS resources?

Enter your email below and check the subscribe box — no message needed. Students get daily practice questions and study tips. Teachers get curriculum resources and teaching strategies.

Typically responds within 24 hours

Message Sent!

Thanks for reaching out. I'll get back to you within 24 hours.

🏫 Welcome, fellow educator!

I offer curriculum resources, practice materials, and study guides designed for AP CS teachers. Let me know what you're looking for — whether it's classroom materials, a guest speaker, or Teachers Pay Teachers resources.

Email

tanner@apcsexamprep.com

📚

Courses

AP CSA, CSP, & Cybersecurity

Response Time

Within 24 hours

Prefer email? Reach me directly at tanner@apcsexamprep.com