{"id":10006322,"date":"2022-08-26T09:36:13","date_gmt":"2022-08-26T01:36:13","guid":{"rendered":"https:\/\/ityet.com\/?p=10006322"},"modified":"2022-08-26T09:36:13","modified_gmt":"2022-08-26T01:36:13","slug":"%e9%9d%a2%e8%af%95%e5%ae%98%ef%bc%9ahashset-%e7%9a%84%e5%ae%9e%e7%8e%b0%e5%8e%9f%e7%90%86%e6%98%af%e6%80%8e%e6%a0%b7%e7%9a%84%ef%bc%9f%e5%ba%95%e5%b1%82%e6%98%af%e4%bb%80%e4%b9%88%e6%95%b0%e6%8d%ae","status":"publish","type":"post","link":"https:\/\/itmax.cn\/?p=10006322","title":{"rendered":"\u9762\u8bd5\u5b98\uff1aHashSet \u7684\u5b9e\u73b0\u539f\u7406\u662f\u600e\u6837\u7684\uff1f\u5e95\u5c42\u662f\u4ec0\u4e48\u6570\u636e\u7ed3\u6784\uff1f\u88ab\u95ee\u5230\u4e86\u3002\u3002"},"content":{"rendered":"<p>\u6765\u6e90\uff1a<a href=\"https:\/\/link.segmentfault.com\/?enc=ogIPLozlzMEXSU3qrUPIyQ%3D%3D.rIHiLA7hk1Oj7GN4HAM6fN4ny33apQCQFgqXtrE0%2FFt0Cw7Nw%2FExx4n36RBQA4TY\" rel=\"nofollow\">https:\/\/www.cnblogs.com\/LiaHo&#8230;<\/a><\/p>\n<h2>\u4e00. HashSet\u6982\u8ff0<\/h2>\n<p>HashSet\u662fJava\u96c6\u5408Set\u7684\u4e00\u4e2a\u5b9e\u73b0\u7c7b\uff0cSet\u662f\u4e00\u4e2a\u63a5\u53e3\uff0c\u5176\u5b9e\u73b0\u7c7b\u9664HashSet\u4e4b\u5916\uff0c\u8fd8\u6709TreeSet\uff0c\u5e76\u7ee7\u627f\u4e86Collection\uff0cHashSet\u96c6\u5408\u5f88\u5e38\u7528\uff0c\u540c\u65f6\u4e5f\u662f\u7a0b\u5e8f\u5458\u9762\u8bd5\u65f6\u7ecf\u5e38\u4f1a\u88ab\u95ee\u5230\u7684\u77e5\u8bc6\u70b9\uff0c\u4e0b\u9762\u662f\u7ed3\u6784\u56fe<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000042380447\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<pre><code class=\"java\">public class HashSet&lt;E&gt;\n    extends AbstractSet&lt;E&gt;\n    implements Set&lt;E&gt;, Cloneable, java.io.Serializable\n{}<\/code><\/pre>\n<h2>\u4e8c. HashSet\u6784\u9020<\/h2>\n<p>HashSet\u6709\u51e0\u4e2a\u91cd\u8f7d\u7684\u6784\u9020\u65b9\u6cd5\uff0c\u6211\u4eec\u6765\u770b\u4e00\u4e0b<\/p>\n<pre><code class=\"java\">private transient HashMap&lt;E,Object&gt; map;\n\/\/\u9ed8\u8ba4\u6784\u9020\u5668\npublic HashSet() {\n    map = new HashMap&lt;&gt;();\n}\n\/\/\u5c06\u4f20\u5165\u7684\u96c6\u5408\u6dfb\u52a0\u5230HashSet\u7684\u6784\u9020\u5668\npublic HashSet(Collection&lt;? extends E&gt; c) {\n    map = new HashMap&lt;&gt;(Math.max((int) (c.size()\/.75f) + 1, 16));\n    addAll(c);\n}\n\/\/\u660e\u786e\u521d\u59cb\u5bb9\u91cf\u548c\u88c5\u8f7d\u56e0\u5b50\u7684\u6784\u9020\u5668\npublic HashSet(int initialCapacity, float loadFactor) {\n    map = new HashMap&lt;&gt;(initialCapacity, loadFactor);\n}\n\/\/\u4ec5\u660e\u786e\u521d\u59cb\u5bb9\u91cf\u7684\u6784\u9020\u5668\uff08\u88c5\u8f7d\u56e0\u5b50\u9ed8\u8ba40.75\uff09\npublic HashSet(int initialCapacity) {\n    map = new HashMap&lt;&gt;(initialCapacity);\n}<\/code><\/pre>\n<p>\u901a\u8fc7\u4e0a\u9762\u7684\u6e90\u7801\uff0c\u6211\u4eec\u53d1\u73b0\u4e86HashSet\u5c31TM\u662f\u4e00\u4e2a\u76ae\u5305\u516c\u53f8\uff0c\u5b83\u5c31\u5bf9\u5916\u63a5\u6d3b\u513f\uff0c\u6d3b\u513f\u63a5\u5230\u4e86\u5c31\u76f4\u63a5\u6254\u7ed9HashMap\u5904\u7406\u4e86\u3002\u56e0\u4e3a\u5e95\u5c42\u662f\u901a\u8fc7HashMap\u5b9e\u73b0\u7684\uff0c\u8fd9\u91cc\u7b80\u5355\u63d0\u4e00\u4e0b:<\/p>\n<p>HashMap\u7684\u6570\u636e\u5b58\u50a8\u662f\u901a\u8fc7\u6570\u7ec4+\u94fe\u8868\/\u7ea2\u9ed1\u6811\u5b9e\u73b0\u7684\uff0c\u5b58\u50a8\u5927\u6982\u6d41\u7a0b\u662f\u901a\u8fc7hash\u51fd\u6570\u8ba1\u7b97\u5728\u6570\u7ec4\u4e2d\u5b58\u50a8\u7684\u4f4d\u7f6e\uff0c\u5982\u679c\u8be5\u4f4d\u7f6e\u5df2\u7ecf\u6709\u503c\u4e86\uff0c\u5224\u65adkey\u662f\u5426\u76f8\u540c\uff0c\u76f8\u540c\u5219\u8986\u76d6\uff0c\u4e0d\u76f8\u540c\u5219\u653e\u5230\u5143\u7d20\u5bf9\u5e94\u7684\u94fe\u8868\u4e2d\uff0c\u5982\u679c\u94fe\u8868\u957f\u5ea6\u5927\u4e8e8\uff0c\u5c31\u8f6c\u5316\u4e3a\u7ea2\u9ed1\u6811\uff0c\u5982\u679c\u5bb9\u91cf\u4e0d\u591f\uff0c\u5219\u9700\u6269\u5bb9\uff08\u6ce8\uff1a\u8fd9\u53ea\u662f\u5927\u81f4\u6d41\u7a0b\uff09\u3002<\/p>\n<p>\u5982\u679c\u5bf9HashMap\u539f\u7406\u4e0d\u592a\u6e05\u695a\u7684\u8bdd\uff0c\u53ef\u4ee5\u5148\u53bb\u4e86\u89e3\u4e00\u4e0b\u3002<\/p>\n<p>\u96c6\u5408\u7cfb\u5217\u6559\u7a0b\uff1a<a href=\"https:\/\/link.segmentfault.com\/?enc=xmKuxVMR%2Ban814vyC8OuKQ%3D%3D.L8YecA%2F3AYMjACxuTT6Iwod99zgac93VvbHliFXA4U9Bg8nidwIHwlUYHXh6LB2V\" rel=\"nofollow\">https:\/\/www.javastack.cn\/cate&#8230;<\/a><\/p>\n<h2>\u4e09. add\u65b9\u6cd5<\/h2>\n<p>HashSet\u7684add\u65b9\u6cd5\u65f6\u901a\u8fc7HashMap\u7684put\u65b9\u6cd5\u5b9e\u73b0\u7684\uff0c\u4e0d\u8fc7HashMap\u662fkey-value\u952e\u503c\u5bf9\uff0c\u800cHashSet\u662f\u96c6\u5408\uff0c\u90a3\u4e48\u662f\u600e\u4e48\u5b58\u50a8\u7684\u5462\uff0c\u6211\u4eec\u770b\u4e00\u4e0b\u6e90\u7801<\/p>\n<pre><code class=\"java\">private static final Object PRESENT = new Object();\n\npublic boolean add(E e) {\n    return map.put(e, PRESENT)==null;\n}<\/code><\/pre>\n<p>\u770b\u6e90\u7801\u6211\u4eec\u77e5\u9053\uff0cHashSet\u6dfb\u52a0\u7684\u5143\u7d20\u662f\u5b58\u653e\u5728HashMap\u7684key\u4f4d\u7f6e\u4e0a\uff0c\u800cvalue\u53d6\u4e86\u9ed8\u8ba4\u5e38\u91cfPRESENT\uff0c\u662f\u4e00\u4e2a\u7a7a\u5bf9\u8c61\u3002<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000042380448\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<h2>\u56db. remove\u65b9\u6cd5<\/h2>\n<p>HashSet\u7684remove\u65b9\u6cd5\u901a\u8fc7HashMap\u7684remove\u65b9\u6cd5\u6765\u5b9e\u73b0<\/p>\n<pre><code class=\"java\">\/\/HashSet\u7684remove\u65b9\u6cd5\npublic boolean remove(Object o) {\n    return map.remove(o)==PRESENT;\n}\n\/\/map\u7684remove\u65b9\u6cd5\npublic V remove(Object key) {\n    Node&lt;K,V&gt; e;\n    \/\/\u901a\u8fc7hash(key)\u627e\u5230\u5143\u7d20\u5728\u6570\u7ec4\u4e2d\u7684\u4f4d\u7f6e\uff0c\u518d\u8c03\u7528removeNode\u65b9\u6cd5\u5220\u9664\n    return (e = removeNode(hash(key), key, null, false, true)) == null ? null : e.value;\n}\n\/**\n *\n *\/\nfinal Node&lt;K,V&gt; removeNode(int hash, Object key, Object value,\n                           boolean matchValue, boolean movable) {\n    Node&lt;K,V&gt;[] tab; Node&lt;K,V&gt; p; int n, index;\n    \/\/\u6b65\u9aa41.\u9700\u8981\u5148\u627e\u5230key\u6240\u5bf9\u5e94Node\u7684\u51c6\u786e\u4f4d\u7f6e\uff0c\u9996\u5148\u901a\u8fc7(n - 1) &amp; hash\u627e\u5230\u6570\u7ec4\u5bf9\u5e94\u4f4d\u7f6e\u4e0a\u7684\u7b2c\u4e00\u4e2anode\n    if ((tab = table) != null &amp;&amp; (n = tab.length) &gt; 0 &amp;&amp;\n        (p = tab[index = (n - 1) &amp; hash]) != null) {\n        Node&lt;K,V&gt; node = null, e; K k; V v;\n        \/\/1.1 \u5982\u679c\u8fd9\u4e2anode\u521a\u597dkey\u503c\u76f8\u540c\uff0c\u8fd0\u6c14\u597d\uff0c\u627e\u5230\u4e86\n        if (p.hash == hash &amp;&amp;\n            ((k = p.key) == key || (key != null &amp;&amp; key.equals(k))))\n            node = p;\n        \/**\n         * 1.2 \u8fd0\u6c14\u4e0d\u597d\uff0c\u5728\u6570\u7ec4\u4e2d\u627e\u5230\u7684Node\u867d\u7136hash\u76f8\u540c\u4e86\uff0c\u4f46key\u503c\u4e0d\u540c\uff0c\u5f88\u660e\u663e\u4e0d\u5bf9\uff0c \u6211\u4eec\u9700\u8981\u904d\u5386\u7ee7\u7eed\n         *     \u5f80\u4e0b\u627e\uff1b\n         *\/\n        else if ((e = p.next) != null) {\n            \/\/1.2.1 \u5982\u679c\u662fTreeNode\u7c7b\u578b\uff0c\u8bf4\u660eHashMap\u5f53\u524d\u662f\u901a\u8fc7\u6570\u7ec4+\u7ea2\u9ed1\u6811\u6765\u5b9e\u73b0\u5b58\u50a8\u7684\uff0c\u904d\u5386\u7ea2\u9ed1\u6811\u627e\u5230\u5bf9\u5e94node\n            if (p instanceof TreeNode)\n                node = ((TreeNode&lt;K,V&gt;)p).getTreeNode(hash, key);\n            else {\n                \/\/1.2.2 \u5982\u679c\u662f\u94fe\u8868\uff0c\u904d\u5386\u94fe\u8868\u627e\u5230\u5bf9\u5e94node\n                do {\n                    if (e.hash == hash &amp;&amp;\n                        ((k = e.key) == key ||\n                         (key != null &amp;&amp; key.equals(k)))) {\n                        node = e;\n                        break;\n                    }\n                    p = e;\n                } while ((e = e.next) != null);\n            }\n        }\n        \/\/\u901a\u8fc7\u524d\u9762\u7684\u6b65\u9aa41\u627e\u5230\u4e86\u5bf9\u5e94\u7684Node,\u73b0\u5728\u6211\u4eec\u5c31\u9700\u8981\u5220\u9664\u5b83\u4e86\n        if (node != null &amp;&amp; (!matchValue || (v = node.value) == value ||\n                             (value != null &amp;&amp; value.equals(v)))) {\n            \/**\n             * \u5982\u679c\u662fTreeNode\u7c7b\u578b\uff0c\u5220\u9664\u65b9\u6cd5\u662f\u901a\u8fc7\u7ea2\u9ed1\u6811\u8282\u70b9\u5220\u9664\u5b9e\u73b0\u7684\uff0c\u5177\u4f53\u53ef\u4ee5\u53c2\u8003\u3010TreeMap\u539f\u7406\u5b9e\u73b0\n             * \u53ca\u5e38\u7528\u65b9\u6cd5\u3011\n             *\/\n            if (node instanceof TreeNode)\n                ((TreeNode&lt;K,V&gt;)node).removeTreeNode(this, tab, movable);\n            \/**\n             * \u5982\u679c\u662f\u94fe\u8868\u7684\u60c5\u51b5\uff0c\u5f53\u627e\u5230\u7684\u8282\u70b9\u5c31\u662f\u6570\u7ec4hash\u4f4d\u7f6e\u7684\u7b2c\u4e00\u4e2a\u5143\u7d20\uff0c\u90a3\u4e48\u8be5\u5143\u7d20\u5220\u9664\u540e\uff0c\u76f4\u63a5\u5c06\u6570\u7ec4\n             * \u7b2c\u4e00\u4e2a\u4f4d\u7f6e\u7684\u5f15\u7528\u6307\u5411\u94fe\u8868\u7684\u4e0b\u4e00\u4e2a\u5373\u53ef\n             *\/\n            else if (node == p)\n                tab[index] = node.next;\n            \/**\n             * \u5982\u679c\u627e\u5230\u7684\u672c\u6765\u5c31\u662f\u94fe\u8868\u4e0a\u7684\u8282\u70b9\uff0c\u4e5f\u7b80\u5355\uff0c\u5c06\u5f85\u5220\u9664\u8282\u70b9\u7684\u4e0a\u4e00\u4e2a\u8282\u70b9\u7684next\u6307\u5411\u5f85\u5220\u9664\u8282\u70b9\u7684\n             * next,\u9694\u79bb\u5f00\u5f85\u5220\u9664\u8282\u70b9\u5373\u53ef\n             *\/\n            else\n                p.next = node.next;\n            ++modCount;\n            --size;\n            \/\/\u5220\u9664\u540e\u53ef\u80fd\u5b58\u5728\u5b58\u50a8\u7ed3\u6784\u7684\u8c03\u6574\uff0c\u53ef\u53c2\u8003\u3010LinkedHashMap\u5982\u4f55\u4fdd\u8bc1\u987a\u5e8f\u6027\u3011\u4e2dremove\u65b9\u6cd5\n            afterNodeRemoval(node);\n            return node;\n        }\n    }\n    return null;\n}<\/code><\/pre>\n<p>removeTreeNode\u65b9\u6cd5\u5177\u4f53\u5b9e\u73b0\u53ef\u53c2\u8003 TreeMap\u539f\u7406\u5b9e\u73b0\u53ca\u5e38\u7528\u65b9\u6cd5<\/p>\n<h2>\u4e94. \u904d\u5386<\/h2>\n<p>HashSet\u4f5c\u4e3a\u96c6\u5408\uff0c\u6709\u591a\u79cd\u904d\u5386\u65b9\u6cd5\uff0c\u5982\u666e\u901afor\u5faa\u73af\uff0c\u589e\u5f3afor\u5faa\u73af\uff0c\u8fed\u4ee3\u5668\uff0c\u6211\u4eec\u901a\u8fc7\u8fed\u4ee3\u5668\u904d\u5386\u6765\u770b\u4e00\u4e0b<\/p>\n<pre><code class=\"java\">public static void main(String[] args) {\n    HashSet&lt;String&gt; setString = new HashSet&lt;&gt; ();\n    setString.add(&quot;\u661f\u671f\u4e00&quot;);\n    setString.add(&quot;\u661f\u671f\u4e8c&quot;);\n    setString.add(&quot;\u661f\u671f\u4e09&quot;);\n    setString.add(&quot;\u661f\u671f\u56db&quot;);\n    setString.add(&quot;\u661f\u671f\u4e94&quot;);\n\n    Iterator it = setString.iterator();\n    while (it.hasNext()) {\n        System.out.println(it.next());\n    }\n}<\/code><\/pre>\n<p>\u6253\u5370\u51fa\u6765\u7684\u7ed3\u679c\u5982\u4f55\u5462\uff1f<\/p>\n<pre><code class=\"java\">\u661f\u671f\u4e8c\n\u661f\u671f\u4e09\n\u661f\u671f\u56db\n\u661f\u671f\u4e94\n\u661f\u671f\u4e00<\/code><\/pre>\n<p>\u610f\u6599\u4e4b\u4e2d\u5427\uff0cHashSet\u662f\u901a\u8fc7HashMap\u6765\u5b9e\u73b0\u7684\uff0cHashMap\u901a\u8fc7hash(key)\u6765\u786e\u5b9a\u5b58\u50a8\u7684\u4f4d\u7f6e\uff0c\u662f\u4e0d\u5177\u5907\u5b58\u50a8\u987a\u5e8f\u6027\u7684\uff0c\u56e0\u6b64HashSet\u904d\u5386\u51fa\u7684\u5143\u7d20\u4e5f\u5e76\u975e\u6309\u7167\u63d2\u5165\u7684\u987a\u5e8f\u3002<\/p>\n<h2>\u516d. \u5408\u8ba1\u5408\u8ba1<\/h2>\n<p>\u6309\u7167\u6211\u524d\u9762\u7684\u89c4\u5212\uff0c\u5e94\u8be5\u6bcf\u4e00\u5757\u4e3b\u8981\u7684\u5185\u5bb9\u90fd\u5355\u72ec\u5199\u4e00\u4e0b\uff0c\u5982\u96c6\u5408ArrayList\uff0cLinkedList\uff0cHashMap\uff0cTreeMap\u7b49\u3002\u4e0d\u8fc7\u6211\u5728\u5199\u8fd9\u7bc7\u5173\u4e8eHashSet\u7684\u6587\u7ae0\u65f6\uff0c\u53d1\u73b0\u6709\u524d\u9762\u5bf9HashMap\u7684\u8bb2\u89e3\u540e\uff0c\u786e\u5b9e\u7b80\u5355\uff0cHashSet\u5c31\u662f\u4e00\u4e2a\u76ae\u5305\u516c\u53f8\uff0c\u5728HashMap\u5916\u9762\u52a0\u4e86\u4e00\u4e2a\u58f3\uff0c\u90a3\u4e48LinkedHashSet\u662f\u5426\u5c31\u662f\u5728LinkedHashMap\u5916\u9762\u52a0\u4e86\u4e00\u4e2a\u58f3\u5462\uff0c\u800cTreeSet\u662f\u5426\u662f\u5728TreeMap\u5916\u9762\u52a0\u4e86\u4e00\u4e2a\u58f3\uff1f\u6211\u4eec\u6765\u9a8c\u8bc1\u4e00\u4e0b<\/p>\n<h3>\u5148\u770b\u4e00\u4e0bLinkedHashSet<\/h3>\n<p>\u6700\u5f00\u59cb\u7684\u7ed3\u6784\u56fe\u5df2\u7ecf\u63d0\u5230\u4e86LinkedHashSet\u662fHashSet\u7684\u5b50\u7c7b\uff0c\u6211\u4eec\u6765\u770b\u6e90\u7801<\/p>\n<pre><code class=\"java\">public class LinkedHashSet&lt;E&gt;\n    extends HashSet&lt;E&gt;\n    implements Set&lt;E&gt;, Cloneable, java.io.Serializable\n{\n\n     public LinkedHashSet(int initialCapacity, float loadFactor) {\n        super(initialCapacity, loadFactor, true);\n    }\n\n    public LinkedHashSet(int initialCapacity) {\n        super(initialCapacity, .75f, true);\n    }\n\n    public LinkedHashSet() {\n        super(16, .75f, true);\n    }\n\n    public LinkedHashSet(Collection&lt;? extends E&gt; c) {\n        super(Math.max(2*c.size(), 11), .75f, true);\n        addAll(c);\n    }\n\n    public Spliterator&lt;E&gt; spliterator() {\n        return Spliterators.spliterator(this, Spliterator.DISTINCT | Spliterator.ORDERED);\n    }\n}<\/code><\/pre>\n<p>\u4e0a\u9762\u5c31\u662fLinkedHashSet\u7684\u6240\u6709\u4ee3\u7801\u4e86\uff0c\u662f\u4e0d\u662f\u611f\u89c9\u667a\u5546\u88ab\u5426\u5b9a\u4e86\uff0c\u8fd9\u57fa\u672c\u4e0a\u6ca1\u5565\u4e1c\u897f\u561b\uff0c\u6784\u9020\u5668\u8fd8\u5168\u90e8\u8c03\u7528\u7236\u7c7b\u7684\uff0c\u4e0b\u9762\u5c31\u662f\u5176\u7236\u7c7bHashSet\u7684\u5bf9\u6b64\u7684\u6784\u9020\u65b9\u6cd5<\/p>\n<pre><code class=\"java\">HashSet(int initialCapacity, float loadFactor, boolean dummy) {\n    map = new LinkedHashMap&lt;&gt;(initialCapacity, loadFactor);\n}<\/code><\/pre>\n<p>\u5927\u5bb6\u4e5f\u770b\u51fa\u6765\uff0c\u548c\u6211\u4eec\u7684\u731c\u6d4b\u4e00\u6837\uff0c\u6ca1\u6709\u6df1\u7a76\u4e0b\u53bb\u7684\u5fc5\u8981\u4e86\u3002\u5982\u679c\u6709\u5174\u8da3\u53ef\u4ee5\u770b\u770bLinkedHashMap\u5982\u4f55\u4fdd\u8bc1\u987a\u5e8f\u6027\u3002<\/p>\n<h3>\u5728\u770b\u4e00\u4e0bTreeSet<\/h3>\n<pre><code class=\"java\">public class TreeSet&lt;E&gt; extends AbstractSet&lt;E&gt;\n    implements NavigableSet&lt;E&gt;, Cloneable, java.io.Serializable\n{\n    public TreeSet() {\n        this(new TreeMap&lt;E,Object&gt;());\n    }\n    public TreeSet(Comparator&lt;? super E&gt; comparator) {\n        this(new TreeMap&lt;&gt;(comparator));\n    }\n    public TreeSet(Collection&lt;? extends E&gt; c) {\n        this();\n        addAll(c);\n    }\n    public TreeSet(SortedSet&lt;E&gt; s) {\n        this(s.comparator());\n        addAll(s);\n    }\n}<\/code><\/pre>\n<p>\u786e\u5b9e\u5982\u6211\u4eec\u6240\u731c\u6d4b\uff0cTreeSet\u4e5f\u5b8c\u5168\u4f9d\u8d56\u4e8eTreeMap\u6765\u5b9e\u73b0\uff0c\u5982\u679c\u6709\u5174\u8da3\u53ef\u4ee5\u770b\u770bTreeMap\u539f\u7406\u5b9e\u73b0\u53ca\u5e38\u7528\u65b9\u6cd5\u3002<\/p>\n<h2>\u4e03. \u603b\u7ed3<\/h2>\n<p>\u672c\u6765\u60f3\u4e09\u7ae0\u7684\u5185\u5bb9\uff0c\u4e00\u7ae0\u5c31\u7b97\u5b8c\u4e86\uff0c\u867d\u7136Set\u5b9e\u73b0\u6709\u70b9\u8d56\u76ae\uff0c\u6bd5\u7adf\u4ed6\u7956\u8f88\u662fCollection\u800c\u4e0d\u662fMap\uff0c\u5728Map\u7684\u5b9e\u73b0\u7c7b\u4e0a\u7a7f\u4e86\u4e00\u5c42\u8863\u670d\u5c31\u6210\u4e86Set\uff0c\u7136\u540e\u51fa\u4e8e\u67d0\u79cd\u76ee\u7684\u57cb\u4f0f\u5728Collection\u4e2d\uff0c\u54c8\u54c8\uff0c\u5f00\u4e2a\u73a9\u7b11\uff0c\u672c\u6587\u4e3b\u8981\u4ecb\u7ecd\u4e86HashSet\u7684\u539f\u7406\u4ee5\u53ca\u4e3b\u8981\u65b9\u6cd5\uff0c\u540c\u65f6\u7b80\u5355\u4ecb\u7ecd\u4e86LinkedHashSet\u548cTreeSet\uff0c\u82e5\u6709\u4e0d\u5bf9\u4e4b\u5904\uff0c\u8bf7\u6279\u8bc4\u6307\u6b63\uff0c\u671b\u5171\u540c\u8fdb\u6b65\uff0c\u8c22\u8c22\uff01<\/p>\n<p><strong>\u8fd1\u671f\u70ed\u6587\u63a8\u8350\uff1a<\/strong><\/p>\n<p>1.<a href=\"https:\/\/link.segmentfault.com\/?enc=%2BJCwWT19CrBgtDp%2BpdXgDA%3D%3D.dH1pPvqdIEmgCVPQmn0FtCSuv5BkZcZX3AjlQebWyCk%3D\" rel=\"nofollow\">1,000+ \u9053 Java\u9762\u8bd5\u9898\u53ca\u7b54\u6848\u6574\u7406(2022\u6700\u65b0\u7248)<\/a><\/p>\n<p>2.<a href=\"https:\/\/link.segmentfault.com\/?enc=KnxpgFYZ2H8hCqgUwtY8oA%3D%3D.ZsO4RqDMxdH3wwNxptF2CCl41h12UlshoakOwc5rSSA9c1fLhXI6x9ALQAcAJOKPyA4vbI%2BVGKAO8rTnXhRSuw%3D%3D\" rel=\"nofollow\">\u52b2\u7206\uff01Java \u534f\u7a0b\u8981\u6765\u4e86\u3002\u3002\u3002<\/a><\/p>\n<p>3.<a href=\"https:\/\/link.segmentfault.com\/?enc=iuJQ7ouzSSWo5oMKrDJyBA%3D%3D.f%2Bc4e8xcX0zmGIvHeGVyeSauX4f7sNdW455GVm%2B1kN8l1gkwOJwZjaX%2FzAu2E3lc\" rel=\"nofollow\">Spring Boot 2.x \u6559\u7a0b\uff0c\u592a\u5168\u4e86\uff01<\/a><\/p>\n<p>4.<a href=\"https:\/\/link.segmentfault.com\/?enc=jUWZT%2BOJyxuS8K9uMyh9PA%3D%3D.I2EUIoLtMJY%2Fe%2B1Q4DrYhjdtxPjXS0BT94C2WDf7MJU%2BzphM3mj6Ejr0QEper1l3EjssPBKy0u55O4mkAEOIBA%3D%3D\" rel=\"nofollow\">\u522b\u518d\u5199\u6ee1\u5c4f\u7684\u7206\u7206\u7206\u70b8\u7c7b\u4e86\uff0c\u8bd5\u8bd5\u88c5\u9970\u5668\u6a21\u5f0f\uff0c\u8fd9\u624d\u662f\u4f18\u96c5\u7684\u65b9\u5f0f\uff01\uff01<\/a><\/p>\n<p>5.<a href=\"https:\/\/link.segmentfault.com\/?enc=vtYuk9U1RZTipY4hl73yvA%3D%3D.S%2FoJH3YQQW2praJg1XdkAAQ7JRbd1UX3asvul0xyvBvPuayRgGzrUbJ7Fd8X5Ldzw8SilLxbuC3FF5g%2F9NUmx1%2BYTEj1gIrG0eSMLE5%2FXO0%3D\" rel=\"nofollow\">\u300aJava\u5f00\u53d1\u624b\u518c\uff08\u5d69\u5c71\u7248\uff09\u300b\u6700\u65b0\u53d1\u5e03\uff0c\u901f\u901f\u4e0b\u8f7d\uff01<\/a><\/p>\n<p>\u89c9\u5f97\u4e0d\u9519\uff0c\u522b\u5fd8\u4e86\u968f\u624b\u70b9\u8d5e+\u8f6c\u53d1\u54e6\uff01<\/p>\n<p><a href=\"https:\/\/segmentfault.com\/a\/1190000042380445\">https:\/\/segmentfault.com\/a\/1190000042380445<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6765\u6e90\uff1ahttps:\/\/www.cnblogs.com\/LiaHo&#8230; \u4e00. HashSet\u6982\u8ff0 Ha [&hellip;]<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[],"tags":[],"class_list":["post-10006322","post","type-post","status-publish","format-standard","hentry"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10006322","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10006322"}],"version-history":[{"count":0,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10006322\/revisions"}],"wp:attachment":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10006322"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10006322"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10006322"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}