QuestionQ34

Working with Streams and Lambda expressions

Given this code fragment:

Question Image

What is the result?

  • A ABBCDE // the order of elements is unpredictable
  • B ABCDE
  • C ABCDE // the order of elements is unpredictable
  • D ADEABCB // the order of elements is unpredictable
Explanation

distinct() retains one occurrence of each value, so the elements are A, B, C, D, and E. On a parallel stream, forEach() does not guarantee encounter order; therefore, all five values are printed once, but their order is unpredictable. Oracle Stream API

Learn more

Community Discussion

No comments yet. Be the first to start the discussion!