Skills101
← All practice quizzes

Quiz: Lambdas and Functional Interfaces

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

Go beyond the basics of lambdas. Every lambda syntax form, the java.util.function family, combining functions with andThen, compose and and/or, the four kinds of method references, and capturing variables.

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.function.*;
    public class Main {
        public static void main(String[] args) {
            Function<Integer, Integer> f = x -> x + 1;
            Function<Integer, Integer> g = x -> x * 2;
            System.out.println(f.andThen(g).apply(5) + " " + f.compose(g).apply(5));
        }
    }
    
  2. Question 2

    Which interface fits a lambda that takes nothing and returns a value?

  3. Question 3

    Which interface is the best fit for (a, b) -> a + b on two Integers giving an Integer?

  4. Question 4

    What does this print?

    import java.util.function.*;
    public class Main {
        public static void main(String[] args) {
            Predicate<String> longWord = s -> s.length() > 4;
            Predicate<String> startsJ = s -> s.startsWith("J");
            System.out.println(longWord.or(startsJ).test("Java") + " " + longWord.and(startsJ).test("Java"));
        }
    }
    
  5. Question 5

    Which method reference is the same as s -> s.trim()?

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