This is wrong. Both the hotspot JDK and OpenJDK implementation uses a native O(nm) algorithm for contains operation. Not a Boyer–Moore string which is O(n). So worst case can be 40 * sizeof(search key) * average_sizeof(keys)
【在 g*****g 的大作中提到】 : This is wrong. Both the hotspot JDK and OpenJDK implementation uses a native : O(nm) algorithm for contains operation. Not a Boyer–Moore string which is : O(n). : So worst case can be 40 * sizeof(search key) * average_sizeof(keys) : : compare
p*i
12 楼
上面是general speaking, 回到你的问题本身, 如果object本身是string的话, 重点就是看hash string --》 index 的cost 和compare two strings的cost了 这个对java熟的人可以具体分析下 好了, 我也要问个问题了, 大家帮忙看下
【在 g*****g 的大作中提到】 : This is wrong. Both the hotspot JDK and OpenJDK implementation uses a native : O(nm) algorithm for contains operation. Not a Boyer–Moore string which is : O(n). : So worst case can be 40 * sizeof(search key) * average_sizeof(keys) : : compare
g*g
16 楼
说的是JDK里 String.contains是一个O(nm)时间复杂度的实现,不是最好的算法。
【在 m****r 的大作中提到】 : contains() for what? : : native : is
m*r
17 楼
yes. i understand all this. but again, the question i am asking is, at how many strings does the linear scan becomes slower.
Depends. Usually a Map uses hash table and thus depends on how you calculate the hashcode for a string. Therefore, your map's performance will vary for different values in your array because the default String.hashCode depends on the char sequence.