[英]HashSet internally uses hashmap for its implementation, then why is hashmap faster than hashset?
HashSet internally uses hashmap for its implementation, then why is hashmap faster than hashset? HashSet内部使用hashmap实现,那么为什么hashmap比hashset更快?
I tried reading the above mentioned post in search but was unable to find a clear answer 我尝试在搜索中阅读上述帖子,但无法找到明确的答案
Because HashSet uses a HashMap. 因为HashSet使用HashMap。 It must incur the cost of using a HashMap, plus the overhead of the HashSet itself.
它必须承担使用HashMap的成本,加上HashSet本身的开销。
in a HashMap
you store element value pairs when in a Set
you store only element. 在
HashMap
您可以在Set
only store only元素中存储元素值对。
When you call add(value)
for Set
actually you call put
as well (for HashMap
). 当你为
Set
调用add(value)
,你也调用了put
(对于HashMap
)。
Set
backed by HashMap
Set
背靠 HashMap
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.