实验
实验代码
package HashCcollision; import java.util.HashSet; import java.util.Set; /** * @author chaird * @create 2022-07-31 22:08 */ public class App {![请添加图片描述](https://ucc.alicdn.com/images/user-upload-01/46fe066444bd429b8762056191dade0c.png) public static void main(String[] args) { Set<Integer> set = new HashSet<>(); int hashcode = 0; // 10w int size = 11 * 10000; System.out.println("init :" + size); for (int i = 0; i < size; i++) { hashcode = new Object().hashCode(); if (set.contains(hashcode)) { System.out.println("第" + i + "次出现了 哈希冲突"); } else { set.add(hashcode); } } System.out.println("finish :" + set.size()); } }
实验结果
如下图所示, 当数量量达到10W~11W的时候会出现哈希碰撞
结论
10W5K左右的量级会出现哈希碰撞