Java OCA OCP Practice Question 2975

Question

What will be the result of executing this code segment?

Stream.of("ace ", "jack ", "queen ", "king ", "joker ")
        .mapToInt(card -> card.length())
        .filter(len -> len > 3)
        .peek(System.out::print)
        .limit(2);
  • a) this code segment prints: jack queen king joker
  • b) this code segment prints: jack queen
  • c) this code segment prints: king joker
  • d) this code segment does not print anything on the console


d)

Note

the limit() method is an intermediate operation and not a terminal operation.

Since there is no terminal operation in this code segment, elements are not processed in the stream and hence it does not print anything on the console.




PreviousNext

Related