使用工具类Arrays.asList()把数组转为集合时,Arrays.asList()返回的ArrayList对象
但是这个ArrayList类不是java.util.ArrayList类 而是Arrays的静态内部类
其中使用了适配器模式,实现部分集合的方法,但由于底层仍然是数组,因此没有实现能改变原数组大小的方法
比如add,remove所以在直接调用时,会抛出UnSupportedOperationException的异常
一下为jdk源码有关此部分的注释
* <p>The returned list implements the optional {@code Collection} methods, except
* those that would change the size of the returned list. Those methods leave
* the list unchanged and throw {@link UnsupportedOperationException}.