List interface, Set interfaces, Map Interface: which added a static method of, you can add more than one time to a set of elements
Use conditions: when the number stored in the collection of elements has been determined, no change
Note: 1.of method is only applied to the above three interfaces, does not apply to the interface implementation class, class does not implement the method of
The return value is a 2.of method can not change the set , can not use the set of add, put the like to change the elements in the set, an exception is thrown
3.set interfaces and map of the interface when you call the method, you can not have duplicate elements, otherwise it will throw an exception
public static void main(String[] args) { List<String> list = List.of("a", "b", "c", "d"); System.out.println(list); // list.add("e"); // java.lang.UnsupportedOperationException // Set<String> set = Set.of("a", "b", "b", "c", "d"); // java.lang.IllegalArgumentException Set<String> set = Set.of("a", "b", "c", "d"); System.out.println(set); // set.add("e"); // java.lang.An UnsupportedOperationException //the Map <String, Integer> Map.of Map = ( "San", 12, "Wang Wu," 34, "Wang Wu", 18);// java.lang.IllegalArgumentException Map<String, Integer> map = Map.of("张三", 12, "李四", 16, "王五", 34); System.out.println(map); // java.lang.UnsupportedOperationException // map.put("lily", 25); // java.lang.UnsupportedOperationException // map.remove("王五"); // java.lang.UnsupportedOperationException }