ArrayList 数组 初始化方法
https://blog.csdn.net/u011523796/article/details/79537055
ArrayList初始化方法:
1、Arrays.asList
ArrayList<Type> obj = new ArrayList<Type>(Arrays.asList(Object o1, Object o2, Object o3, ....so on));
2、生成匿名内部内进行初始化
ArrayList<T> obj = new ArrayList<T>() {{ add(Object o1); add(Object o2); ... ... }};
3、常规方式
ArrayList<T> obj = new ArrayList<T>(); obj.add("o1"); obj.add("o2"); ... ...
或者
ArrayList<T> obj = new ArrayList<T>(); List list = Arrays.asList("o1","o2",...); obj.addAll(list);
4、Collections.ncopies
ArrayList<T> obj = new ArrayList<T>(Collections.nCopies(count,element));//把element复制count次填入ArrayList中
数组初始化方法:
String[] STR_MOOD = new String[]{"兴奋","开心","轻松","平静","无助","忧伤","不安","暴躁"};