Performance: Creating an ArrayList from HashMap.values()

后端 未结 5 711
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-12 10:58

Question is how much it costs to create an ArrayList from a HashMap.values() Collection? Or creating the values Collection alone? Assuming Map.size() > 100k. Objects could also

5条回答
  •  时光说笑
    2021-02-12 11:16

    You can use an Iterator to skip elements - just call next() many times.

    Creating a list of any collection has a linear complexity.

提交回复
热议问题