Arrays.asList()将数组转换为集合:
String[] myArray = { "Apple", "Banana", "Orange" };
List<String> myList = Arrays.asList(myArray);
//上面两个语句等价于下面一条语句
List<String> myList = Arrays.asList("Apple","Banana", "Orange");
注意:
Arrays.asList()
将数组转换为集合后,底层其实还是数组,不能使用其修改集合的相关方法,它的add/remove/clear方法会抛出异常
如何正确将数组转换为ArrayList
List list = new ArrayList<>(Arrays.asList("a", "b", "c"))