Collections.binarySearch() vs. List indexOf()

前端 未结 3 1434
既然无缘
既然无缘 2021-01-02 05:26

I have a list of more than 37K items, and I already implemented hashCode(), equals(), so I wonder Collections.binarySearch() can help

3条回答
  •  执笔经年
    2021-01-02 06:09

    If your collection is sorted, binarySearch() will be O(log n) as opposed to indexOf()'s O(n) and you will definitely see an improvement.

提交回复
热议问题