Given the code fragment:
List
String fmt = codes.stream()
.filter (s-> s.contains ("PEG"))
.reduce((s, t) -> s + t).get();
System.out.println("\n" + fmt);
What is the result?
Given the code fragment:
List
String fmt = codes.stream()
.filter (s-> s.contains ("PEG"))
.reduce((s, t) -> s + t).get();
System.out.println("\n" + fmt);
What is the result?
The code initializes a list with the values ["DOC", "MPEG", "JPEG"] and then prints each element followed by a space, resulting in 'DOC MPEG JPEG '. The stream filters the elements that contain 'PEG'. Only 'MPEG' and 'JPEG' match this condition. The reduce method concatenates these filtered elements and produces 'MPEGJPEG'. The get() method retrieves this result. Therefore, the complete output is 'DOC MPEG JPEG \nMPEGJPEG'.
A is correct (Tested)
Answer is Correct.
A is the correct answer.Tested
A is correct.
A. Tested