使用 Arrays.asList 转换静态对象数组的成本是多少?假设对象数组有 N 个项目,它只是一个 O(N) 算法,其中所有项目都是通过引用复制的,还是仅仅是将原始数组放在 List 外观后面的外观?
最佳答案
它很便宜,O(1)。正如您怀疑该列表只是数组的包装。 Java API documentation 证实了这一点。 :
Returns a fixed-size list backed by the specified array. (Changes to the returned list "write through" to the array.)
关于java - Arrays.asList 的性能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1552783/