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

Given the code fragment:

List nums = Arrays.asList (10, 20, 8):

System.out.println (

//line n1

);

line n1 to enable the code to print the maximum number in the nums list?

Which code fragment must be inserted at

    Correct Answer: A

    To find the maximum number in the list using Java Streams, you can use the stream method max along with a Comparator. The correct code fragment to do this is nums.stream().max(Comparator.comparing(a -> a)).get(). This finds the maximum element in the stream based on natural ordering and returns it.

Discussion
DestroyerOption: A

Answer is A

asdfjhfgjuaDCVOption: A

A is the correct answer import java.util.Arrays; import java.util.Comparator; import java.util.List; public class Main { public static void main(String[] args) { List<Integer> nums = Arrays.asList(10, 20, 8); System.out.println("Maximum number: " + nums.stream() .max(Comparator.comparing(a -> a)) .get()); } }

iSnoverOption: A

Answer is A. Tested.

steefaandOption: A

A is correct.

AlazemOption: A

A, tested