测试代码:
String[] array = {"1","2","3"}; List<String> list = Arrays.asList(array); // list.add("4"); list.remove(0);
这个时候会报错 Exception in thread "main" java.lang.UnsupportedOperationException
解决办法:array-->java.util.Arrays.ArrayList-->java.util.ArrayList
String[] array = {"1","2","3"}; List<String> list = new ArrayList<>(Arrays.asList(array)); list.add("4"); list.remove(0); System.out.println(list);
注意:new ArrayList(ArrayList),调用的并不是初始化大小那个方法,调用的是: