Collections.singletonList(something)
是不可变的,
而Arrays.asList(something)
是List和Array在堆中加入的Array的一个固定大小的List
表示形式。
Arrays.asList(something)
允许Arrays.asList(something)
更改 ,这反映到List和联合数组中。
它会抛出UnsupportedOperationException
用于添加,删除元素,尽管您可以为特定索引设置元素。
对Collections.singletonList(something)
返回的列表所做的任何更改将导致UnsupportedOperationException
。
此外,由Collections.singletonList(something)
返回的List的容量将始终为1,
而Arrays.asList(something)
的容量将为已支持数组的大小。