Given the code fragment:
What is the result?
Given the code fragment:
What is the result?
The given code segment involves creating two lists: list1, which is modifiable, and list2, which is created using List.copyOf(list1). The List.copyOf() method returns an unmodifiable (immutable) copy of the given list. When the code attempts to sort list2, it will throw a java.lang.UnsupportedOperationException since an immutable list cannot be modified. Therefore, the result is a java.lang.UnsupportedOperationException being thrown.
List.copyOf() returns un-modifiable list.
C , because an immutable list cannot be sorted or modified
Tested: C.
Answer: C
C is correct
List.copyOf() returns immutable list.
c correct