ArrayList Methods FRQ Practice

Responses receive AI feedback against a rubric after submission. Scores are practice estimates.

Question 1 of 5

A print shop stores ink names in a list.

(a) Write the import for ArrayList and construct ArrayList<String> names = new ArrayList<String>(); (b) Add "ink" then "wax" using add(E). (c) State size() and get(0). (d) Explain that ArrayList() starts empty and stores object references.

Question 2 of 5

Complete the table for a lumber rack. Then explain how add(index, obj) shifts later elements.

After statement get(0) get(1) get(2) get(3) size
add("oak") oak none none none 1
add("elm") none none
add(1, "fir") none
add("ash")

Question 3 of 5

A fruit crate starts as lime then plum.

import java.util.ArrayList;
ArrayList<String> crate = new ArrayList<String>();
crate.add("lime");
crate.add("plum");

(a) If the next call is crate.set(1, "pear"), state the new size, get(1), and the value set returns. (b) If instead the original crate used crate.add(1, "pear"), state get(0), get(1), get(2), and size. (c) Explain replace versus insert-and-shift.

Question 4 of 5

Trace two removals from a snack cart. Explain each left shift and the valid indices afterward.

import java.util.ArrayList;
ArrayList<String> cart = new ArrayList<String>();
cart.add("jam");
cart.add("rye");
cart.add("fig");
cart.add("tea");
cart.remove(1);
cart.remove(1);

(a) State the remaining elements in index order and the final size. (b) Identify which String each remove returns. (c) Explain how later elements shift after each remove. (d) List the valid indices after both removals.

Question 5 of 5

A bolt bin uses ArrayList<Integer> and autoboxing.

(a) Construct an empty ArrayList<Integer>, add 5, add 8, then add(1, 2). (b) State get(0), get(1), get(2), and size. (c) Explain autoboxing of those int values. (d) Explain why ArrayList<Integer> is used rather than a primitive int list.