Exactly, Jacqueline! Also, java list.of is designed to be more memory-efficient. Since it creates an immutable list, it eliminates some of the overhead involved in the mutable fixed-size list that Arrays.asList creates. This can lead to better performance, especially when dealing with large datasets.
For example, when you need a lightweight, optimized list for performance, java list.of is the way to go. It’s more efficient because it skips the unnecessary overhead of the ArrayList that Arrays.asList uses under the hood.
List<Integer> fastList = List.of(1, 2, 3, 4, 5); // More efficient
List<Integer> arrayList = Arrays.asList(1, 2, 3, 4, 5); // More overhead
So, if you’re concerned about performance and need immutability, java list.of will serve you much better.