tiffany_dixon
tiffany_dixon Aug 2, 2026 β€’ 10 views

Data Structures Quiz for AP Computer Science A (Java)

Hey future CS whiz! πŸš€ Ready to ace your AP Computer Science A exam? Data structures are super foundational, and mastering them is key. This quick guide and quiz will help you solidify your understanding of Arrays, ArrayLists, and 2D Arrays in Java. Let's dive in! πŸ’‘
πŸ’» Computer Science & Technology
πŸͺ„

πŸš€ Can't Find Your Exact Topic?

Let our AI Worksheet Generator create custom study notes, online quizzes, and printable PDFs in seconds. 100% Free!

✨ Generate Custom Content

1 Answers

βœ… Best Answer
User Avatar
SandyCheeks Mar 16, 2026

πŸ“š Quick Study Guide: AP CSA Data Structures (Java)

  • πŸ“ Arrays:
    • βœ… Fixed-size, contiguous collection of elements of the same data type (primitives or objects).
    • ✍️ Declaration: `dataType[] arrayName = new dataType[size];` Example: `int[] numbers = new int[5];`
    • πŸ” Access elements using an index: `arrayName[index]`. Indices range from 0 to `length - 1`.
    • πŸ”’ Length is accessed via `.length` (e.g., `numbers.length`).
  • πŸ“ˆ ArrayLists:
    • ✨ Dynamic-size, resizable array-like structure that stores objects (cannot store primitives directly).
    • πŸ“ Declaration: `ArrayList listName = new ArrayList();` Example: `ArrayList names = new ArrayList();`
    • βš™οΈ Key Methods:
      • βž• `add(element)`: Appends an element to the end.
      • πŸ“ `add(index, element)`: Inserts an element at a specific index.
      • ➑️ `get(index)`: Returns the element at the specified index.
      • πŸ”„ `set(index, element)`: Replaces the element at the specified index.
      • βœ‚οΈ `remove(index)`: Removes the element at the specified index and shifts subsequent elements.
      • πŸ“Š `size()`: Returns the number of elements in the list.
  • πŸ–ΌοΈ 2D Arrays (Matrices):
    • 🌐 An array of arrays, representing rows and columns.
    • πŸ“‹ Declaration: `dataType[][] matrixName = new dataType[rows][cols];` Example: `int[][] grid = new int[3][4];`
    • 🎯 Access elements using two indices: `matrixName[rowIndex][colIndex]`.
    • πŸ“ Row length: `matrixName.length`. Column length of a specific row: `matrixName[rowIndex].length`.
  • ↔️ Key Differences:
    • πŸ”’ Arrays have a fixed size; πŸ”“ ArrayLists are dynamic.
    • πŸ“¦ Arrays can store primitives and objects; ♻️ ArrayLists only store objects (use wrapper classes for primitives).
    • πŸ“ Arrays use `.length` for size; πŸ“Š ArrayLists use `.size()` method.

πŸ“ Practice Quiz

Choose the best answer for each question.

1. Which of the following is the correct way to declare and initialize an array of 10 integers in Java?

  1. `int[] numbers = {10};`
  2. `int numbers[] = new int[10];`
  3. `int numbers = new int[10];`
  4. `Array numbers = new Array(10);`

2. What will be the output after executing the following Java code snippet?

ArrayList list = new ArrayList<>();
list.add("Apple");
list.add("Banana");
list.add(0, "Cherry");
System.out.println(list.get(1));
  1. `Apple`
  2. `Banana`
  3. `Cherry`
  4. `IndexOutOfBoundsException`

3. Given a 2D array `int[][] matrix = {{1, 2, 3}, {4, 5, 6}};`, what is the value of `matrix[1][0]`?

  1. `1`
  2. `2`
  3. `4`
  4. `5`

4. What is a primary advantage of using an `ArrayList` over a traditional Java array?

  1. `ArrayLists` can store primitive data types directly.
  2. `ArrayLists` have a fixed size, which improves performance.
  3. `ArrayLists` can dynamically resize themselves.
  4. `ArrayLists` allow direct access to elements without using an index.

5. Consider the following `ArrayList`:
`ArrayList nums = new ArrayList<>();`
`nums.add(10); nums.add(20); nums.add(30);`
What is the content of `nums` after `nums.remove(1);` is executed?

  1. `[10, 30]`
  2. `[20, 30]`
  3. `[10, 20]`
  4. `[10, 20, 30]` (no change)

6. Which of the following loops correctly iterates through all elements of an `int[] arr = {1, 2, 3, 4, 5};`?

  1. for (int i = 1; i <= arr.length; i++) {
        System.out.println(arr[i]);
    }
  2. for (int num : arr) {
        System.out.println(num);
    }
  3. for (int i = 0; i < arr.length - 1; i++) {
        System.out.println(arr[i]);
    }
  4. for (int i = 0; i <= arr.length; i++) {
        System.out.println(arr[i]);
    }

7. Given a 2D array `String[][] names = new String[5][3];`, what does `names.length` represent?

  1. The total number of elements in the array.
  2. The number of columns (3).
  3. The number of rows (5).
  4. The length of the first row (which is 3).
Click to see Answers

1. B

2. A (List becomes ["Cherry", "Apple", "Banana"], `list.get(1)` is "Apple")

3. C

4. C

5. A (Original: [10, 20, 30]. Remove index 1 (20) -> [10, 30])

6. B

7. C

Join the discussion

Please log in to post your answer.

Log In

Earn 2 Points for answering. If your answer is selected as the best, you'll get +20 Points! πŸš€