你懂的撒,List集合添加元素很方便,添加元素不方便的情况参见隔壁数组.
然而初始化并不方便,想比之下这点就不如数组了.
那想用集合有讨厌其初始化的怎么办,写代码写着玩的时候偶然想到 , 可采用下面的方式来试试!
比如我们想要一个List<String> :
List<String> ls = Arrays.asList(new String[]{"shiino","mafuyu","yukino","愚蠢的地球人","不科学的电磁炮"});
再比如我们要一个包含String数组的集合 :
List<String[]> ls = Arrays.asList(new String[][]{
{"shiino","mafuyu","yukino","愚蠢的地球人","不科学的电磁炮"},
{"shiino","mafuyu","yukino","愚蠢的地球人","不科学的电磁炮"},
{"shiino","mafuyu","yukino","愚蠢的地球人","不科学的电磁炮"},
{"shiino","mafuyu","yukino","愚蠢的地球人","不科学的电磁炮"}
});
然后就可以愉快的使用list了 O(∩_∩)O哈哈~