java - Arrays.asList 的性能

标签 java performance optimization

使用 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/

相关文章:

java - ENUM 存储(内存等)

javascript - 使用闭包编译器编写更好的面向对象 JavaScript 完整示例代码

Java:为变量分配当前值?

Java jar : Executing a method only upon opening the jar for the first time?

java - hibernate 异常 : proxy handle is no longer valid after database violation error

java - 自动重新加载Tomcat webapp?

node.js - Electron JS启动缓慢

java - 更新其网站的应用程序

php - MySQL 获取一个选择,如果不可用则获取其他

c++ - 如何优化大集合散点的插值?