Given the code fragment:
Which action sorts the book list?
Given the code fragment:
Which action sorts the book list?
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.
B is correct answer. List is immutable