int[] intArr = new int[]{1,2,3,4,5,9};
String[] strArr = {"张三","李四","王二麻"};
int[] price = new int[4]; price[0] = 99; price[1] = 101; ......
List<String> jdks = Arrays.asList("JDK6", "JDK8", "JDK10");
List<String> names = new ArrayList<>() {{ add("Tom"); add("Sally"); add("John"); }};
List<String> colors = Stream.of("blue", "red", "yellow").collect(toList());
List<String> cups = List.of("A", "B", "C");
这种方式添加的是不可变的、复制某个元素N遍的工具类
List<String> apples = Collections.nCopies(3, "apple");
HashMap<String, String > myMap = new HashMap<String, String>(){{ put("a","b"); put("b","b"); }};
Map.of("Hello", 1, "World", 2);//不可变集合
Map<String, Integer> myMap = ImmutableMap.of("a", 1, "b", 2, "c", 3);
原文:https://www.cnblogs.com/liang1101/p/14783263.html