QuizzesFunctional Interfaces — Concept Check
intermediate
java

Functional Interfaces — Concept Check

Questions on Functional Interfaces. Master the java.util.function package — Predicate, Function, Consumer, Supplier, and their Bi and primitive variants used throughout the Streams API.

8 minutes 8 questions Pass at 70%
Time Limit
8 minutes - timer starts when you begin
Change Answers Freely
Revisit and change any answer before submitting
Full Review After Submit
Correct answers and explanations shown for every question
Auto-submit on timeout
Quiz submits automatically when time runs out

Questions in this quiz

8 questions on Functional Interfaces — Concept Check. Work through them here, then start the quiz to answer them and see your score.

  1. 1.A developer wants to filter a list of strings to only include those that start with 'A' and are longer than 5 characters. Which functional interface should they use?

    • AConsumer<String>
    • BSupplier<String>
    • CFunction<String, Boolean>
    • DPredicate<String>
  2. 2.A method reference is used in Java to bridge between OOP methods and functional programming. Which of the following is a valid method reference for a static method?

    • AClassName::instanceMethod
    • BClassName::staticMethod
    • CClassName::new
    • Dinstance::instanceMethod
  3. 3.In a performance-critical application, a developer uses Predicate<Integer> to check if numbers are even. What is a better alternative?

    • ASupplier<Boolean>
    • BFunction<Integer, Boolean>
    • CBiPredicate<Integer, Integer>
    • DIntPredicate
  4. 4.A developer wants to create a function that takes two integers and returns their sum. Which functional interface should they use?

    • ABiFunction<Integer, Integer, Integer>
    • BIntBinaryOperator
    • CFunction<Integer, Integer>
    • DBinaryOperator<Integer>
  5. 5.A service logs messages and also saves them to a file. Which functional interface allows chaining these operations?

    • AConsumer<String>
    • BSupplier<String>
    • CPredicate<String>
    • DFunction<String, Void>
  6. 6.A developer uses Function<String, Integer> to get the length of a string. What method can they use to chain this with another function that doubles the length?

    • AandThen
    • Bapply
    • Ccompose
    • Daccept
  7. 7.A developer needs a function that returns a new ArrayList every time it's called. Which functional interface is appropriate?

    • ASupplier<List<String>>
    • BConsumer<List<String>>
    • CPredicate<List<String>>
    • DFunction<Void, List<String>>
  8. 8.Which of the following functional interfaces extends BiFunction<T, T, T>?

    • AFunction<T, T>
    • BBiConsumer<T, T>
    • CBiPredicate<T, T>
    • DBinaryOperator<T>