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