Using List.of for immutable list with single element instead of Collections.singletonList
问题 Java 9 introduce factory methods to create immutable lists with List.of . Which is more suitable to create an immutable list of one element ? List<String> immutableList1 = List.of("one"); List<String> immutableList2 = Collections.singletonList("one"); 回答1: Prefer using factory method List<String> immutableList1 = List.of("one"); Because they disallow null elements is one of the benefit and also factory methods in List interface are handy to add multiple objects and creates immutable List They