Skip to content
Quiz · Lambdas and the Stream API · lesson 2 of 12

Quiz — a lambda changes a variable

What happens when this program is compiled and run?

JAVA
import java.util.List;

public class Main {
    public static void main(String[] args) {
        List<Integer> xs = List.of(1, 2, 3);
        int total = 0;
        xs.forEach(x -> total += x);
        System.out.println(total);
    }
}