数组转成list:
方法一:
String[] userid = {"aa","bb","cc"};
List<String> userList = new ArrayList<String>();
Collections.addAll(userList, userid);
方法二:
String[] userid = {"aa","bb","cc"};
List<String> userList = Arrays.asList(userid);
另:Arrays.asList()返回一个受指定数组支持的固定大小的列表。所以不能做Add、Remove等操作。
List list = new ArrayList(Arrays.asList(userid));这样操作就可以了。
方法三:
String[] userid = {"aa","bb","cc"};
List<String> userList = new ArrayList<String>(userid.length);
for(String uid: userid){
userList.add(uid);
}
list转化成数组:
方法一:
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]);
方法二:
List<String> strList = new ArrayList<String>();
strList.add("aa");
strList.add("bb");
String[] strs = new String[strList.size()];