โ† All 1Z0-819 Flashcard Decks

Stream API 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 Stream API flashcards as text
  1. What does Stream.of("a","b","c").reduce("", (x,y) -> x + y) return?

    Answer: abc

    The two-argument reduce() with an identity value returns the result directly (not wrapped in Optional).

  2. Which of the following is a stateful intermediate operation?

    Answer: sorted()

    sorted() must process all elements before emitting any, making it stateful; the others can process elements one at a time.

  3. What is the output of Stream.of(3,1,4,1,5).distinct().sorted().findFirst().orElse(-1)?

    Answer: 1

    distinct() gives 3,1,4,5; sorted() gives 1,3,4,5; findFirst() returns Optional[1], orElse(-1) returns 1.

  4. Which Collectors method produces a Map counting elements per group?

    Answer: Collectors.groupingBy(classifier, Collectors.counting())

    Collectors.groupingBy with a downstream Collectors.counting() produces a Map where each key maps to the count of matching elements.

  5. What does Stream.empty() return when collect(Collectors.toList()) is called?

    Answer: An empty List

    Stream.empty() has no elements, so collecting to a list produces an empty (non-null) List.

  6. Which method should be used to process a stream element for side effects without changing the stream?

    Answer: peek()

    peek() is an intermediate operation designed for side-effect inspection (e.g., debugging) while passing elements downstream unchanged.

  7. What is the result of LongStream.rangeClosed(1, 4).average()?

    Answer: OptionalDouble[2.5]

    rangeClosed(1,4) produces 1,2,3,4; average() returns OptionalDouble[2.5].