Skills101
← All practice quizzes

Quiz: Java 8 Lambdas and Streams

5 questionsNo time limitPass: 60%+10 XP on first pass

Write modern Java: lambda expressions, functional interfaces, method references, the Stream API (filter, map, reduce, collect, groupingBy) and Optional.

Log in to take the quiz

Free account · see your score, answers and explanations, earn XP

  1. Question 1

    What does this print?

    import java.util.*;
    public class Main {
        public static void main(String[] args) {
            List<Integer> l = List.of(1, 2, 3, 4, 5);
            System.out.println(l.stream().filter(x -> x % 2 == 1).map(x -> x * 10).toList());
        }
    }
    
  2. Question 2

    Which functional interface returns a boolean?

  3. Question 3

    When does a stream pipeline actually run?

  4. Question 4

    What does this print?

    import java.util.*;
    public class Main {
        public static void main(String[] args) {
            System.out.println(List.of(2, 3, 4).stream().reduce(0, Integer::sum));
        }
    }
    
  5. Question 5

    Which is the method reference for s -> s.length()?