一、数组转化为list
1、
String[] userid = {"aa","bb","cc"};
List<String> userList = new ArrayList<String>();
Collections.addAll(userList, userid);
2、String[] userid = {"aa","bb","cc"};
List<String> strList = new ArrayList<String>(Arrays.asList(userid ));
and、
String[] userid = {"aa","bb","cc"};
List<String> userList = new ArrayList<String>(userid.length);
for(String uid: userid){
userList.add(uid);
}
二、list转数组1、
List<String> strList = new ArrayList<String>();
strList.add("aa");
strList.add("bb");
Object[] objs = strList.toArray();
如果要变成String数组,需要强转类型。
String[] strs = (String[]) strList.toArray();
也可以指定大小:
final int size = strList.size();
String[] strs = (String[])strList.toArray(new String[size]);
and、
List<String> strList = new ArrayList<String>();
strList.add("aa");
trList.add("bb");
String[] strs = new String[strList.size()];