简体   繁体   中英

Performance of Arrays.asList

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?

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.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM