โ† All 1Z0-819 Flashcard Decks

Functional Interfaces Flashcards

7 cards from real 1Z0-819 practice questions. Tap to flip, then mark Knew It or Still Learning โ€” missed cards come back until you master them.

Read the first 7 Functional Interfaces flashcards as text
  1. Which primitive-specialised functional interface avoids boxing when mapping an `int` to an `int`?

    Answer: IntUnaryOperator

    IntUnaryOperator operates on primitive int values without boxing, whereas the other options involve wrapper types.

  2. What is the difference between `IntFunction` and `ToIntFunction`?

    Answer: IntFunction takes an int and returns R; ToIntFunction takes T and returns an int

    IntFunction accepts a primitive int and produces a result R; ToIntFunction accepts any T and produces a primitive int.

  3. Which interface does `UnaryOperator` extend?

    Answer: Function

    UnaryOperator extends Function, specialising it for the case where input and output types are the same.

  4. What does `BinaryOperator.maxBy(Comparator comparator)` return?

    Answer: A BinaryOperator that returns the greater of two elements according to the comparator

    BinaryOperator.maxBy returns a BinaryOperator that returns the larger of its two operands as determined by the given Comparator.

  5. Which of the following correctly declares a `DoubleSupplier` lambda?

    Answer: DoubleSupplier ds = () -> 3;

    DoubleSupplier's abstract method getAsDouble() takes no arguments and returns a double; the integer literal 3 is widened automatically.

  6. What is the abstract method of `LongBinaryOperator`?

    Answer: applyAsLong(long left, long right)

    LongBinaryOperator defines a single abstract method applyAsLong(long left, long right) returning a primitive long.

  7. Which functional interface should you prefer for `x -> x * 2` when `x` is a primitive `int`, to avoid autoboxing?

    Answer: IntUnaryOperator

    IntUnaryOperator works entirely with primitive int values via applyAsInt(), eliminating all boxing overhead.