Arrays.asList的性能 [英] Performance of Arrays.asList

查看:447
本文介绍了Arrays.asList的性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Arrays.asList转换静态对象数组的成本是多少?假设对象数组有N个项目,只是O(N)算法,其中所有项目都是通过引用复制的,还是仅仅是将原始数组放在List门面后面的门面?

What is the cost of using Arrays.asList to convert static object arrays? Assuming that the object array has N items is it just an O(N) algorithm, where all of the items are copied by reference or is it merely a facade where the original array is put behind a List facade?

推荐答案

它很便宜,O(1).您可能会怀疑列表只是数组的包装器.这已通过 Java API文档:

It is cheap, O(1). As you suspect the list is merely a wrapper around the array. This is confirmed by the Java API documentation:

返回由指定数组支持的固定大小的列表. (将返回的列表更改为直写"到数组.)

Returns a fixed-size list backed by the specified array. (Changes to the returned list "write through" to the array.)

这篇关于Arrays.asList的性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆