From my experience, one of the key distinctions lies in immutability. When you use java list.of, it creates an immutable list, which means that once it’s created, you can’t modify the contents—no adding, removing, or updating the elements. If you try to modify the list, you’ll get an UnsupportedOperationException. For example:
List<Integer> list1 = List.of(1, 2, 3); // Immutable
list1.add(4); // Throws UnsupportedOperationException
In contrast, Arrays.asList returns a fixed-size list. You can modify the elements, but you can’t add or remove any items. For instance:
List<Integer> list2 = Arrays.asList(1, 2, 3); // Fixed size
list2.set(0, 99); // Works fine
list2.add(4); // Throws UnsupportedOperationException
So, if you need a list that should never be modified, java list.of is definitely the better choice.