1.静态初始化数组
String[] names = new String[]{"aaa","bbb","ccc"};
2.静态初始化list
List<String> stringList = new LinkedList<String>(){{
add("a");
add("b");
add("c");
}};
或者用 Array.asList
List<String> stringList = Arrays.asList("a", "b", "c");
3.静态初始化HashSet
HashSet<String> nameSet= new HashSet<String>() {{
add("aaa");
add("bbb");
add("ccc");
}};
4.静态初始化HashMap
Map<Character, String> numMap = new HashMap<Character, String>() {{
put('2', "abc");
put('3', "def");
put('4', "ghi");
put('5', "jkl");
put('6', "mno");
put('7', "pqrs");
put('8', "tuv");
put('9', "wxyz");
}};