Java Topic Practice
ArrayList Basics
Practice mode with 15 Java-focused questions, immediate answer checks, and explanations.
For practice use only.
ArrayList Basics MCQ Practice
ArrayList Basics Java practice with 15 questions, code tracing, and a worked explanation for every answer.
Question 1 of 15
Answered 0 of 15
Choose one answer.
Code Tracing 01 - ArrayList Basics: track the final printed value.
import java.util.ArrayList;
public class Main {
public static void main(String[] args) {
ArrayList<Integer> nums = new ArrayList<Integer>();
nums.add(3);
nums.add(7);
nums.add(3);
nums.add(9);
nums.add(5);
nums.set(1, nums.get(0) + nums.get(2));
int moved = nums.remove(3);
nums.add(1, moved);
int total = 0;
for (int i = 0; i < nums.size(); i++) {
if (i % 2 == 0) total += nums.get(i);
else total -= nums.get(i);
}
System.out.print(nums + ":" + total);
}
}