Skills101
← All practice quizzes

Quiz: Java Streams in Depth

5 questions · new set on every retakeNo time limitPass: 60%+10 XP on first pass

Go beyond filter and map. How a stream really runs (lazily, one element at a time), toMap with duplicate keys, groupingBy with counting and averaging, partitioningBy, flatMap, reduce and IntStream.

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.of(5, 12, 8, 20).stream()
                .filter(n -> { System.out.print(n + " "); return n > 10; })
                .findFirst();
            System.out.println();
        }
    }
    
  2. Question 2

    What happens when Collectors.toMap(key, value) meets two elements with the same key?

  3. Question 3

    Which collector gives, for each city, how many students live there?

  4. Question 4

    What does this print?

    import java.util.*;
    import java.util.stream.*;
    public class Main {
        public static void main(String[] args) {
            List<List<Integer>> a = List.of(List.of(1, 2), List.of(3), List.of());
            System.out.println(a.stream().flatMap(List::stream).mapToInt(Integer::intValue).sum());
        }
    }
    
  5. Question 5

    What is special about partitioningBy compared with groupingBy?

🎯 Today’s placement challenge — 10 questions, no login. Can you score 10/10?Take today’s challenge →