List和Arrays.asList的坑

String[] a = {"A","B","C"};
String[] b = {"D","E"};

//执行OK
List list = new ArrayList(Arrays.asList(a));
list.addAll(Arrays.asList(b));//ok

//执行异常
//List list = Arrays.asList(a);
//list.addAll(Arrays.asList(b));//java.lang.UnsupportedOperationException

String[] str = new String[list.size()];
list.toArray(str);    
for(int x=0;x

具体原因,可以参考如下博客:

https://www.cnblogs.com/wang-meng/p/f1532cf23ce049ce63b4bdd62d53659d.html

你可能感兴趣的:(Java,服务器端开发)