Exam 1z0-809 All QuestionsBrowse all questions from this exam
Question 59

Given the code fragment:

List codes = Arrays.asList ("DOC", "MPEG", "JPEG"); codes.forEach (c -> System.out.print(c + " "));

String fmt = codes.stream()

.filter (s-> s.contains ("PEG"))

.reduce((s, t) -> s + t).get();

System.out.println("\n" + fmt);

What is the result?

    Correct Answer: A

    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'.

Discussion
DestroyerOption: A

A is correct (Tested)

thetech

Answer is Correct.

asdfjhfgjuaDCVOption: A

A is the correct answer.Tested

steefaandOption: A

A is correct.

WilsonKKerllOption: A

A. Tested