Java OCA OCP Practice Question 2117

Question

Choose the correct option based on this code segment:.

"abracadabra".chars().distinct().peek(ch -> System.out .printf("%c ", ch)).sorted();
  • a . it prints: "a b c d r"
  • B. it prints: "a b r c d"
  • C. it crashes by throwing a java.util.IllegalFormatConversionException
  • d. this program terminates normally without printing any output in the console


d.

Note

a stream pipeline is lazily evaluated.

since there is no terminal operation provided (such as count, forEach, reduce, or collect), this pipeline is not evaluated and hence the peek does not print any output to the console.




PreviousNext

Related