โ† All AP CSA Flashcard Decks

Arrays and ArrayLists Flashcards

6 cards from real AP CSA practice questions. Tap to flip, then mark Knew It or Still Learning โ€” missed cards come back until you master them.

Read the first 6 Arrays and ArrayLists flashcards as text
  1. What happens if you try to store a double value in an int array in Java?

    Answer: Compile-time error

    Java is strongly typed; storing a double in an int array causes a compile-time type mismatch error.

  2. How do you get the number of rows in a 2D array called `matrix`?

    Answer: matrix.length

    For a 2D array, `matrix.length` gives the number of rows (outer array length).

  3. Which ArrayList method removes the first occurrence of a specified object?

    Answer: remove(Object o)

    ArrayList.remove(Object o) removes the first occurrence of the specified element from the list.

  4. What is traversing a 2D array row by row called?

    Answer: Row-major order traversal

    Iterating through a 2D array row by row (outer loop over rows) is called row-major order traversal.

  5. What is the default value of elements in a newly created `int[]` array?

    Answer: 0

    Java initializes all elements of a numeric array to 0 by default when created with `new`.

  6. Which of the following correctly converts an ArrayList to an array?

    Answer: list.toArray(new Integer[0])

    The toArray(T[] a) method of ArrayList returns an array containing all elements; passing `new Integer[0]` specifies the type.