Java OCA OCP Practice Question 2213

Introduction

Choose the best 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 code segment 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() method does not print any output to the console.




PreviousNext

Related