Performance: Creating an ArrayList from HashMap.values()

后端 未结 5 1479
感动是毒
感动是毒 2021-02-12 10:32

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:01

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

    Creating a list of any collection has a linear complexity.

提交回复
热议问题