Performance: Creating an ArrayList from HashMap.values()

后端 未结 5 1371
感动是毒
感动是毒 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:06

    To elaborate on @Bozho's solution you can just do.

    int count = 0;
    for(Value value: map.values())
       if(count++ % 5 == 0)
         // do something.
    

提交回复
热议问题