在HashSet中,存储对象(元素或值)
例:如果我们有一个字符串元素的HashSet,那么它可以描述一个
HashSet元素集合:{" Hello ", " Hi ", " Bye ", " Run "}
HashSet不允许重复表示您的元素
不能在HashSet中存储重复的值。李< / >
HashSet允许有一个空值。
HashSet没有同步,这意味着除非显式同步,否则它们不适合线程安全操作。
add contains next notes
HashSet O(1) O(1) O(h/n) h is the table
HashMap
HashMap class implements the Map interface
HashMap is
used for storing key & value pairs. In short, it maintains the
mapping of key & value (The HashMap class is roughly equivalent to
Hashtable, except that it is unsynchronized and permits nulls.) This
is how you could represent HashMap elements if it has integer key
and value of String type: e.g. {1->”Hello”, 2->”Hi”, 3->”Bye”,
4->”Run”}
HashMap does not allow duplicate keys however it allows having duplicate values.
HashMap permits single null key and any number of null values.
HashMap is not synchronized which means they are not suitable for thread-safe operations until unless synchronized explicitly.[similarity]
get containsKey next Notes
HashMap O(1) O(1) O(h/n) h is the table
Please refer this article to find more information.