Return to site

JAVA CERTIFICATION QUESTION: Stream collect and StringBuilder

· java,ocp


What is the output?

  • A. abc
  • B. acb
  • C. bac
  • D. bca
  • E. cab
  • F. cba
  • G. cacb
  • H. cbca

#java #certificationquestion #ocp

Here, the stream is sequential, meaning the combiner function doesn't have any effect (it is used only in parallel processing).

The supplier function, the first collect parameter, creates a StringBuilder instance with the initial value "c".

The accumulator, the second collect parameter, appends two elements and returns the built StringBuilder.

In the end, we got "cab".



·Ǝ sᴉ ɹǝʍsuɐ ʇɔǝɹɹoɔ ǝɥʇ :uoᴉsnʅɔuoꓛ