Performance of Arrays.asList

前端 未结 1 1206
孤街浪徒
孤街浪徒 2020-12-25 11:14

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

相关标签:
1条回答
  • 2020-12-25 11:57

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

    0 讨论(0)
提交回复
热议问题