Exam 1z0-829 All QuestionsBrowse all questions from this exam
Question 48

Given the code fragment:

Which action sorts the book list?

    Correct Answer: B

    The method List.of() returns an immutable list, which means the list cannot be modified after it is created. The sort() method of the List interface requires the list to be mutable because it tries to modify the list in place. Therefore, converting the books type to a mutable ArrayList type at Line n1 will allow the sort() method to work, properly sorting the list based on the titles of the books.

Discussion
xplorerpjOption: B

B is correct answer. List is immutable