Java Learner logo
← Back to all exercises

Collections

Iterating an ArrayList

Predict exactly what the console prints after the loop runs.

Collections

Iterating an ArrayList

BeginnerAwaiting attempt

Predict exactly what the console prints after the loop runs.

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

public class Main {
    public static void main(String[] args) {
        List<String> tools = new ArrayList<>();
        tools.add("Java");
        tools.add("Kotlin");
        tools.add(1, "Scala");
        tools.remove("Java");

        for (String tool : tools) {
            System.out.println(tool);
        }
    }
}