Java ArrayList Quiz

This Java quiz covers ArrayList, the list you will use most. You will predict what add(), set(), remove() and indexOf() do, see why List.of() refuses changes and learn which operations are fast.

Easy 10 questions ~5 minutes Pass at 80% Java 17

Choose a mode

Playing as a guest: sign in to keep your XP and streak.

Sample question

Question 1 of 10

What does this print?

import java.util.ArrayList;
import java.util.List;

public class Main {
    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        list.add("a");
        list.add("b");
        list.add(0, "c");
        System.out.println(list);
    }
}
Show the answer

B. [c, a, b] add(x) appends at the end, but add(0, x) inserts at index 0 and shifts the others right. So c ends up first.

What this quiz covers

  • add(), add(index, x) and set()
  • get(), indexOf() and lastIndexOf()
  • remove(Object) and out-of-range indexes
  • List.of() and Arrays.asList() limits
  • Generics need wrapper types like Integer

Questions people ask

Do I need an account?

No. Anyone can play. Sign in to keep your XP, streak, badges and history.

Can I retake it?

Yes. Your best score is kept, and the questions and answers are shuffled each time.