标签:一个 java out rem oar arraylist strong system port
数组转集合<list是Arrays里面的一个静态内部类,该类并未实现add、remove方法>
List<String> list = Arrays.asList(arr);
数组转集合
String[] arr = new String[]{"hello","world"}; List<String> list = new ArrayList<String>(Arrays.asList(arr));
集合转数组
String[] array=list.toArray(new String[list.size()]);
遇见的问题
1.泛型的重要性 1
int[] arr = new int[]{1,2,3,4,5}; List list = Arrays.asList(arr); System.out.println(list.size());
2.数组转集合add报错 java.lang.UnsupportedOperationException
Integer[] arr = new Integer[]{1,2,3,4,5}; List<Integer> list = Arrays.asList(arr);
list.add(6); System.out.println(list.size());
标签:一个 java out rem oar arraylist strong system port
原文地址:https://www.cnblogs.com/likaixin/p/11165491.html