Fastest data structure for contains() in Java?(Java中包含()的最快数据结构?)
问题描述
Java 中对 contains() 运算速度最快的数据结构是什么?
What's the data structure in Java that has the fastest operation for contains() ?
例如我有一组数字 { 1, 7, 12, 14, 20... }
e.g. i have a set of numbers { 1, 7, 12, 14, 20... }
给定另一个任意数字 x,生成 x 是否包含在集合中的布尔值的最快方法(平均而言)是什么?!contains() 的概率大约高出 5 倍.
Given another arbitrary number x, what's the fastest way (on average) to generate the boolean value of whether x is contained in the set or not? The probability for !contains() is about 5x higher.
所有的map结构都提供o(1)操作吗?HashSet 是最快的方法吗?
Do all the map structures provide o(1) operation? Is HashSet the fastest way to go?
推荐答案
查看基于集合 (Hashset, enumset) 和哈希 (HashMap,linkedhash...,idnetityhash..) 的实现.他们有 O(1) for contains()
look at set (Hashset, enumset) and hash (HashMap,linkedhash...,idnetityhash..) based implementations. they have O(1) for contains()
这份备忘单很有帮助.
这篇关于Java中包含()的最快数据结构?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Java中包含()的最快数据结构?


基础教程推荐
- 大摇大摆的枚举 2022-01-01
- Java Swing计时器未清除 2022-01-01
- 多个组件的复杂布局 2022-01-01
- 如何在 Spring @Value 注解中正确指定默认值? 2022-01-01
- 如何在 JFrame 中覆盖 windowsClosing 事件 2022-01-01
- 不推荐使用 Api 注释的描述 2022-01-01
- 在 Java 中创建日期的正确方法是什么? 2022-01-01
- 从 python 访问 JVM 2022-01-01
- Java 实例变量在两个语句中声明和初始化 2022-01-01
- 验证是否调用了所有 getter 方法 2022-01-01