Quiz · Lambdas and the Stream API · lesson 12 of 12
Quiz — orElse
What does the program print?
import java.util.List;
public class Main {
public static void main(String[] args) {
List<Integer> xs = List.of(1, 3, 5);
int r = xs.stream()
.filter(x -> x % 2 == 0)
.findFirst()
.orElse(-1);
System.out.println(r);
}
}