Difference in lambda performances?

前端 未结 3 1965
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-02 20:33

This is not a duplicate of my question. I checked it and it is more about inner anonymous classes.

I was curious about Lambda expressions and tested the following :

3条回答
  •  时光说笑
    2021-01-02 21:11

    Because remove(index) is very expensive :) It needs to copy and shift the rest of elements, and this is done multiple times in your case.

    While removeIf(filter) does not need to do that. It can sweep once and mark all elements to be deleted; then the final phase copies survivors to the head of list just once.

提交回复
热议问题