They are entirely different constructs. A HashMap is an implementation of Map. A Map maps keys to values. The key look up occurs using the hash.
On the other hand, a HashSet is an implementation of Set. A Set is designed to match the mathematical model of a set. A HashSet does use a HashMap to back its implementation, as you noted. However, it implements an entirely different interface.
HashMap:
http://www.pakzilla.com/2009/08/24/hashmap-vs-hashtable-vs-hashset/
本文深入解析了HashMap与HashSet之间的区别及联系。HashMap是一种实现Map接口的数据结构,通过哈希值来查找键值对;而HashSet作为Set接口的一种实现,利用HashMap来支持其内部操作,保证了元素的唯一性。尽管两者都依赖于哈希机制,但它们的设计目标和服务的场景却截然不同。
4691

被折叠的 条评论
为什么被折叠?



