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

Given the code fragment:

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

System.out.println (

//line n1

);

Which code fragment must be inserted at line n1 to enable the code to print the maximum number in the nums list?

    Correct Answer: A

    The correct code fragment to print the maximum number in the nums list is nums.stream().max(Comparator.comparing(a -> a)).get(). This uses a stream to compare each element and find the maximum value based on natural ordering.

Discussion
YasinGaberOption: A

A, tested. B will give the first number in the array list. C & D will give compilation error.

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()); } }

steefaandOption: A

Can confirm that correct answer is A. Tested.

r1muka5Option: A

Answer is A

YasinGaberOption: A

A, tested

Svetleto13Option: A

A,tested

AVB22

I confirm