Return to site

JAVA CERTIFICATION QUESTION: Streams and flatMap operations in Java

· java

The powerful peek() function can be tricky to use correctly in Java streams.

Given the code fragment:

String[][] arr = {{"a", "d"}, {"n", "d"}, {"a", "x"}};
Arrays.stream(arr)
  .peek(v -> v.equals(new String[] {"a", "d"}))
  .flatMap(u -> Arrays.stream(u))
  .forEach(System.out::print);

What is the output? Choose one.

A. ad

B. [a,d]

C. anaddx

D. adndax

E. [[a,d][n,d][a,x]]

F. Compilation fails due to the argument to peek.

 

 

 

 

 

·ꓷ uoᴉʇdo sᴉ ɹǝʍsuɐ ʇɔǝɹɹoɔ ǝɥꓕ ·uoᴉsnʅɔuoꓛ