Collections.binarySearch()与清单的indexOf() [英] Collections.binarySearch() vs. List indexOf()

查看:121
本文介绍了Collections.binarySearch()与清单的indexOf()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有超过37K的项目清单,我已经实现了散code()等于(),所以我不知道 Col​​lections.binarySearch()有助于提高性能和比的indexOf()方法。

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

推荐答案

如果您的收藏进行排序,的binarySearch()将是O(log n)的,而不是的indexOf()的O(N),你一定会看到一个进步。

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.

这篇关于Collections.binarySearch()与清单的indexOf()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆