简体   繁体   English

HashSet内部使用hashmap实现,那么为什么hashmap比hashset更快?

[英]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.

相关问题 为什么HashMap比HashSet更快? - Why is HashMap faster than HashSet? 为什么Sun Java中的HashSet实现使用HashMap作为支持? - Why does HashSet implementation in Sun Java use HashMap as its backing? HashSet 内部只使用 HashMap 但为什么我们要使用 hashSet 而不是 hashMap? - Internally HashSet is using HashMap only but why we are going for hashSet instead of hashMap? hashmap或hashset? - hashmap or hashset? 我知道HashSet在内部用作HashMap和HashMap - I know HashSet Internally work as HashMap and HashMap internally 我们知道HashSet在内部作为HashMap起作用,因此在打印Hashset Object时,元素为何进入数组? - We know that HashSet internally work as HashMap so while printing Hashset Object why element comes in array? 为什么HashSet的内部实现会创建虚拟对象以在HashMap中作为值插入而不是插入空值? - Why the internal implementation of HashSet creates dummy objects to insert as values in HashMap rather than inserting nulls? java.util.HashMap和HashSet的内部实现 - Internal implementation of java.util.HashMap and HashSet HashMap是否使用HashSet来存储其密钥? - Does a HashMap use a HashSet to store its keys? 为什么HashSet不能仅在内部使用位数组而不是HashMap来节省一些空间? - Why can’t HashSet just use bit array internally instead of HashMap to save some space?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM