{"id":505,"date":"2019-03-08T14:27:24","date_gmt":"2019-03-08T06:27:24","guid":{"rendered":"https:\/\/fick707.com\/?p=505"},"modified":"2019-03-08T14:28:28","modified_gmt":"2019-03-08T06:28:28","slug":"hashmap-data-structure","status":"publish","type":"post","link":"https:\/\/fick707.com\/?p=505","title":{"rendered":"HashMap\u7684\u5b9e\u73b0\u539f\u7406\u548c\u5e95\u5c42\u7ed3\u6784"},"content":{"rendered":"<p>\u54c8\u5e0c\u8868\uff08hash table\uff09\u4e5f\u53eb\u6563\u5217\u8868\uff0c\u662f\u4e00\u79cd\u975e\u5e38\u91cd\u8981\u7684\u6570\u636e\u7ed3\u6784\uff0c\u5e94\u7528\u573a\u666f\u53ca\u5176\u4e30\u5bcc\uff0c\u8bb8\u591a\u7f13\u5b58\u6280\u672f\uff08\u6bd4\u5982memcached\uff09\u7684\u6838\u5fc3\u5176\u5b9e\u5c31\u662f\u5728\u5185\u5b58\u4e2d\u7ef4\u62a4\u4e00\u5f20\u5927\u7684\u54c8\u5e0c\u8868\uff0c\u800cHashMap\u7684\u5b9e\u73b0\u539f\u7406\u4e5f\u5e38\u5e38\u51fa\u73b0\u5728\u5404\u7c7b\u7684\u9762\u8bd5\u9898\u4e2d\uff0c\u91cd\u8981\u6027<a href=\"https:\/\/www.baidu.com\/s?wd=%E5%8F%AF%E8%A7%81%E4%B8%80%E6%96%91&amp;tn=24004469_oem_dg&amp;rsv_dl=gh_pl_sl_csd\" target=\"_blank\" rel=\"noopener noreferrer\">\u53ef\u89c1\u4e00\u6591<\/a>\u3002\u672c\u6587\u4f1a\u5bf9java\u96c6\u5408\u6846\u67b6\u4e2d\u7684\u5bf9\u5e94\u5b9e\u73b0HashMap\u7684\u5b9e\u73b0\u539f\u7406\u8fdb\u884c\u8bb2\u89e3\uff0c\u7136\u540e\u4f1a\u5bf9JDK7\u7684HashMap\u6e90\u7801\u8fdb\u884c\u5206\u6790\u3002<\/p>\n<p>\u76ee\u5f55<\/p>\n<p>\u4e00\u3001<a href=\"http:\/\/www.cnblogs.com\/chengxiao\/p\/6059914.html#t1\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">\u4ec0\u4e48\u662f\u54c8\u5e0c\u8868<\/a><\/p>\n<p>\u4e8c\u3001<a href=\"http:\/\/www.cnblogs.com\/chengxiao\/p\/6059914.html#t2\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">HashMap\u5b9e\u73b0\u539f\u7406<\/a><\/p>\n<p>\u4e09\u3001<a href=\"http:\/\/www.cnblogs.com\/chengxiao\/p\/6059914.html#t3\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">\u4e3a\u4f55HashMap\u7684\u6570\u7ec4\u957f\u5ea6\u4e00\u5b9a\u662f2\u7684\u6b21\u5e42\uff1f<\/a><\/p>\n<p>\u56db\u3001<a href=\"http:\/\/www.cnblogs.com\/chengxiao\/p\/6059914.html#t4\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">\u91cd\u5199equals\u65b9\u6cd5\u9700\u540c\u65f6\u91cd\u5199hashCode\u65b9\u6cd5<\/a><\/p>\n<p>\u4e94\u3001<a href=\"http:\/\/www.cnblogs.com\/chengxiao\/p\/6059914.html#t5\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">\u603b\u7ed3<\/a><\/p>\n<h1><a name=\"t0\"><\/a><a target=\"_blank\" name=\"t1\" rel=\"noopener noreferrer\"><\/a>\u4e00\u3001\u4ec0\u4e48\u662f\u54c8\u5e0c\u8868<\/h1>\n<p>\u5728\u8ba8\u8bba\u54c8\u5e0c\u8868\u4e4b\u524d\uff0c\u6211\u4eec\u5148\u5927\u6982\u4e86\u89e3\u4e0b\u5176\u4ed6\u6570\u636e\u7ed3\u6784\u5728\u65b0\u589e\uff0c\u67e5\u627e\u7b49\u57fa\u7840\u64cd\u4f5c\u6267\u884c\u6027\u80fd<\/p>\n<p>\u6570\u7ec4\uff1a\u91c7\u7528\u4e00\u6bb5\u8fde\u7eed\u7684\u5b58\u50a8\u5355\u5143\u6765\u5b58\u50a8\u6570\u636e\u3002\u5bf9\u4e8e\u6307\u5b9a\u4e0b\u6807\u7684\u67e5\u627e\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3aO(1)\uff1b\u901a\u8fc7\u7ed9\u5b9a\u503c\u8fdb\u884c\u67e5\u627e\uff0c\u9700\u8981\u904d\u5386\u6570\u7ec4\uff0c\u9010\u4e00\u6bd4\u5bf9\u7ed9\u5b9a\u5173\u952e\u5b57\u548c\u6570\u7ec4\u5143\u7d20\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3aO(n)\uff0c\u5f53\u7136\uff0c\u5bf9\u4e8e\u6709\u5e8f\u6570\u7ec4\uff0c\u5219\u53ef\u91c7\u7528\u4e8c\u5206\u67e5\u627e\uff0c\u63d2\u503c\u67e5\u627e\uff0c\u6590\u6ce2\u90a3\u5951\u67e5\u627e\u7b49\u65b9\u5f0f\uff0c\u53ef\u5c06\u67e5\u627e\u590d\u6742\u5ea6\u63d0\u9ad8\u4e3aO(logn)\uff1b\u5bf9\u4e8e\u4e00\u822c\u7684\u63d2\u5165\u5220\u9664\u64cd\u4f5c\uff0c\u6d89\u53ca\u5230\u6570\u7ec4\u5143\u7d20\u7684\u79fb\u52a8\uff0c\u5176\u5e73\u5747\u590d\u6742\u5ea6\u4e5f\u4e3aO(n)<\/p>\n<p>\u7ebf\u6027\u94fe\u8868\uff1a\u5bf9\u4e8e\u94fe\u8868\u7684\u65b0\u589e\uff0c\u5220\u9664\u7b49\u64cd\u4f5c\uff08\u5728\u627e\u5230\u6307\u5b9a\u64cd\u4f5c\u4f4d\u7f6e\u540e\uff09\uff0c\u4ec5\u9700\u5904\u7406\u7ed3\u70b9\u95f4\u7684\u5f15\u7528\u5373\u53ef\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3aO(1)\uff0c\u800c\u67e5\u627e\u64cd\u4f5c\u9700\u8981\u904d\u5386\u94fe\u8868\u9010\u4e00\u8fdb\u884c\u6bd4\u5bf9\uff0c\u590d\u6742\u5ea6\u4e3aO(n)<\/p>\n<p>\u4e8c\u53c9\u6811\uff1a\u5bf9\u4e00\u68f5\u76f8\u5bf9\u5e73\u8861\u7684\u6709\u5e8f\u4e8c\u53c9\u6811\uff0c\u5bf9\u5176\u8fdb\u884c\u63d2\u5165\uff0c\u67e5\u627e\uff0c\u5220\u9664\u7b49\u64cd\u4f5c\uff0c\u5e73\u5747\u590d\u6742\u5ea6\u5747\u4e3aO(logn)\u3002<\/p>\n<p>\u54c8\u5e0c\u8868\uff1a\u76f8\u6bd4\u4e0a\u8ff0\u51e0\u79cd\u6570\u636e\u7ed3\u6784\uff0c\u5728\u54c8\u5e0c\u8868\u4e2d\u8fdb\u884c\u6dfb\u52a0\uff0c\u5220\u9664\uff0c\u67e5\u627e\u7b49\u64cd\u4f5c\uff0c\u6027\u80fd\u5341\u5206\u4e4b\u9ad8\uff0c\u4e0d\u8003\u8651\u54c8\u5e0c\u51b2\u7a81\u7684\u60c5\u51b5\u4e0b\uff0c\u4ec5\u9700\u4e00\u6b21\u5b9a\u4f4d\u5373\u53ef\u5b8c\u6210\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3aO(1)\uff0c\u63a5\u4e0b\u6765\u6211\u4eec\u5c31\u6765\u770b\u770b\u54c8\u5e0c\u8868\u662f\u5982\u4f55\u5b9e\u73b0\u8fbe\u5230\u60ca\u8273\u7684\u5e38\u6570\u9636O(1)\u7684\u3002<\/p>\n<p>\u6211\u4eec\u77e5\u9053\uff0c\u6570\u636e\u7ed3\u6784\u7684\u7269\u7406\u5b58\u50a8\u7ed3\u6784\u53ea\u6709\u4e24\u79cd\uff1a\u987a\u5e8f\u5b58\u50a8\u7ed3\u6784\u548c\u94fe\u5f0f\u5b58\u50a8\u7ed3\u6784\uff08\u50cf\u6808\uff0c\u961f\u5217\uff0c\u6811\uff0c\u56fe\u7b49\u662f\u4ece\u903b\u8f91\u7ed3\u6784\u53bb\u62bd\u8c61\u7684\uff0c\u6620\u5c04\u5230\u5185\u5b58\u4e2d\uff0c\u4e5f\u8fd9\u4e24\u79cd\u7269\u7406\u7ec4\u7ec7\u5f62\u5f0f\uff09\uff0c\u800c\u5728\u4e0a\u9762\u6211\u4eec\u63d0\u5230\u8fc7\uff0c\u5728\u6570\u7ec4\u4e2d\u6839\u636e\u4e0b\u6807\u67e5\u627e\u67d0\u4e2a\u5143\u7d20\uff0c\u4e00\u6b21\u5b9a\u4f4d\u5c31\u53ef\u4ee5\u8fbe\u5230\uff0c\u54c8\u5e0c\u8868\u5229\u7528\u4e86\u8fd9\u79cd\u7279\u6027\uff0c\u54c8\u5e0c\u8868\u7684\u4e3b\u5e72\u5c31\u662f\u6570\u7ec4\u3002<\/p>\n<p>\u6bd4\u5982\u6211\u4eec\u8981\u65b0\u589e\u6216\u67e5\u627e\u67d0\u4e2a\u5143\u7d20\uff0c\u6211\u4eec\u901a\u8fc7\u628a\u5f53\u524d\u5143\u7d20\u7684\u5173\u952e\u5b57 \u901a\u8fc7\u67d0\u4e2a\u51fd\u6570\u6620\u5c04\u5230\u6570\u7ec4\u4e2d\u7684\u67d0\u4e2a\u4f4d\u7f6e\uff0c\u901a\u8fc7\u6570\u7ec4\u4e0b\u6807\u4e00\u6b21\u5b9a\u4f4d\u5c31\u53ef\u5b8c\u6210\u64cd\u4f5c\u3002<\/p>\n<p>\u5b58\u50a8\u4f4d\u7f6e = f(\u5173\u952e\u5b57)<\/p>\n<p>\u5176\u4e2d\uff0c\u8fd9\u4e2a\u51fd\u6570f\u4e00\u822c\u79f0\u4e3a\u54c8\u5e0c\u51fd\u6570\uff0c\u8fd9\u4e2a\u51fd\u6570\u7684\u8bbe\u8ba1\u597d\u574f\u4f1a\u76f4\u63a5\u5f71\u54cd\u5230\u54c8\u5e0c\u8868\u7684\u4f18\u52a3\u3002\u4e3e\u4e2a\u4f8b\u5b50\uff0c\u6bd4\u5982\u6211\u4eec\u8981\u5728\u54c8\u5e0c\u8868\u4e2d\u6267\u884c\u63d2\u5165\u64cd\u4f5c\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/images2015.cnblogs.com\/blog\/1024555\/201611\/1024555-20161113180447499-1953916974.png\" alt=\"\" width=\"768\" height=\"354\" \/><\/p>\n<p>\u67e5\u627e\u64cd\u4f5c\u540c\u7406\uff0c\u5148\u901a\u8fc7\u54c8\u5e0c\u51fd\u6570\u8ba1\u7b97\u51fa\u5b9e\u9645\u5b58\u50a8\u5730\u5740\uff0c\u7136\u540e\u4ece\u6570\u7ec4\u4e2d\u5bf9\u5e94\u5730\u5740\u53d6\u51fa\u5373\u53ef\u3002<\/p>\n<p>\u54c8\u5e0c\u51b2\u7a81<\/p>\n<p>\u7136\u800c\u4e07\u4e8b\u65e0\u5b8c\u7f8e\uff0c\u5982\u679c\u4e24\u4e2a\u4e0d\u540c\u7684\u5143\u7d20\uff0c\u901a\u8fc7\u54c8\u5e0c\u51fd\u6570\u5f97\u51fa\u7684\u5b9e\u9645\u5b58\u50a8\u5730\u5740\u76f8\u540c\u600e\u4e48\u529e\uff1f\u4e5f\u5c31\u662f\u8bf4\uff0c\u5f53\u6211\u4eec\u5bf9\u67d0\u4e2a\u5143\u7d20\u8fdb\u884c\u54c8\u5e0c\u8fd0\u7b97\uff0c\u5f97\u5230\u4e00\u4e2a\u5b58\u50a8\u5730\u5740\uff0c\u7136\u540e\u8981\u8fdb\u884c\u63d2\u5165\u7684\u65f6\u5019\uff0c\u53d1\u73b0\u5df2\u7ecf\u88ab\u5176\u4ed6\u5143\u7d20\u5360\u7528\u4e86\uff0c\u5176\u5b9e\u8fd9\u5c31\u662f\u6240\u8c13\u7684\u54c8\u5e0c\u51b2\u7a81\uff0c\u4e5f\u53eb\u54c8\u5e0c\u78b0\u649e\u3002\u524d\u9762\u6211\u4eec\u63d0\u5230\u8fc7\uff0c\u54c8\u5e0c\u51fd\u6570\u7684\u8bbe\u8ba1\u81f3\u5173\u91cd\u8981\uff0c\u597d\u7684\u54c8\u5e0c\u51fd\u6570\u4f1a\u5c3d\u53ef\u80fd\u5730\u4fdd\u8bc1\u00a0\u8ba1\u7b97\u7b80\u5355\u548c\u6563\u5217\u5730\u5740\u5206\u5e03\u5747\u5300,\u4f46\u662f\uff0c\u6211\u4eec\u9700\u8981\u6e05\u695a\u7684\u662f\uff0c\u6570\u7ec4\u662f\u4e00\u5757\u8fde\u7eed\u7684\u56fa\u5b9a\u957f\u5ea6\u7684\u5185\u5b58\u7a7a\u95f4\uff0c\u518d\u597d\u7684\u54c8\u5e0c\u51fd\u6570\u4e5f\u4e0d\u80fd\u4fdd\u8bc1\u5f97\u5230\u7684\u5b58\u50a8\u5730\u5740\u7edd\u5bf9\u4e0d\u53d1\u751f\u51b2\u7a81\u3002\u90a3\u4e48\u54c8\u5e0c\u51b2\u7a81\u5982\u4f55\u89e3\u51b3\u5462\uff1f\u54c8\u5e0c\u51b2\u7a81\u7684\u89e3\u51b3\u65b9\u6848\u6709\u591a\u79cd:\u5f00\u653e\u5b9a\u5740\u6cd5\uff08\u53d1\u751f\u51b2\u7a81\uff0c\u7ee7\u7eed\u5bfb\u627e\u4e0b\u4e00\u5757\u672a\u88ab\u5360\u7528\u7684\u5b58\u50a8\u5730\u5740\uff09\uff0c\u518d\u6563\u5217\u51fd\u6570\u6cd5\uff0c\u94fe\u5730\u5740\u6cd5\uff0c\u800cHashMap\u5373\u662f\u91c7\u7528\u4e86\u94fe\u5730\u5740\u6cd5\uff0c\u4e5f\u5c31\u662f\u6570\u7ec4+\u94fe\u8868\u7684\u65b9\u5f0f\uff0c<\/p>\n<h1><a name=\"t1\"><\/a><a target=\"_blank\" name=\"t2\" rel=\"noopener noreferrer\"><\/a>\u4e8c\u3001HashMap\u5b9e\u73b0\u539f\u7406<\/h1>\n<p>HashMap\u7684\u4e3b\u5e72\u662f\u4e00\u4e2aEntry\u6570\u7ec4\u3002Entry\u662fHashMap\u7684\u57fa\u672c\u7ec4\u6210\u5355\u5143\uff0c\u6bcf\u4e00\u4e2aEntry\u5305\u542b\u4e00\u4e2akey-value\u952e\u503c\u5bf9\u3002<\/p>\n<div class=\"cnblogs_code\">\n<pre>\/\/HashMap\u7684\u4e3b\u5e72\u6570\u7ec4\uff0c\u53ef\u4ee5\u770b\u5230\u5c31\u662f\u4e00\u4e2aEntry\u6570\u7ec4\uff0c\u521d\u59cb\u503c\u4e3a\u7a7a\u6570\u7ec4{}\uff0c\u4e3b\u5e72\u6570\u7ec4\u7684\u957f\u5ea6\u4e00\u5b9a\u662f2\u7684\u6b21\u5e42\uff0c\u81f3\u4e8e\u4e3a\u4ec0\u4e48\u8fd9\u4e48\u505a\uff0c\u540e\u9762\u4f1a\u6709\u8be6\u7ec6\u5206\u6790\u3002\ntransient Entry&lt;K,V&gt;[] table = (Entry&lt;K,V&gt;[]) EMPTY_TABLE;<\/pre>\n<\/div>\n<p>Entry\u662fHashMap\u4e2d\u7684\u4e00\u4e2a\u9759\u6001\u5185\u90e8\u7c7b\u3002\u4ee3\u7801\u5982\u4e0b<\/p>\n<div class=\"cnblogs_code\">\n<div class=\"cnblogs_code_toolbar\"><span class=\"cnblogs_code_copy\"><a title=\"\u590d\u5236\u4ee3\u7801\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" src=\"http:\/\/common.cnblogs.com\/images\/copycode.gif\" alt=\"\u590d\u5236\u4ee3\u7801\" \/><\/a><\/span><\/div>\n<pre>    static class Entry&lt;K,V&gt; implements Map.Entry&lt;K,V&gt; {\n        final K key;\n        V value;\n        Entry&lt;K,V&gt; next;\/\/\u5b58\u50a8\u6307\u5411\u4e0b\u4e00\u4e2aEntry\u7684\u5f15\u7528\uff0c\u5355\u94fe\u8868\u7ed3\u6784\n        int hash;\/\/\u5bf9key\u7684hashcode\u503c\u8fdb\u884chash\u8fd0\u7b97\u540e\u5f97\u5230\u7684\u503c\uff0c\u5b58\u50a8\u5728Entry\uff0c\u907f\u514d\u91cd\u590d\u8ba1\u7b97\n\n        \/**\n         * Creates new entry.\n         *\/\n        Entry(int h, K k, V v, Entry&lt;K,V&gt; n) {\n            value = v;\n            next = n;\n            key = k;\n            hash = h;\n        }<\/pre>\n<div class=\"cnblogs_code_toolbar\"><span class=\"cnblogs_code_copy\"><a title=\"\u590d\u5236\u4ee3\u7801\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" src=\"http:\/\/common.cnblogs.com\/images\/copycode.gif\" alt=\"\u590d\u5236\u4ee3\u7801\" \/><\/a><\/span><\/div>\n<\/div>\n<p>\u6240\u4ee5\uff0cHashMap\u7684\u6574\u4f53\u7ed3\u6784\u5982\u4e0b<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/images2015.cnblogs.com\/blog\/1024555\/201611\/1024555-20161113235348670-746615111.png\" alt=\"\" width=\"934\" height=\"566\" \/><\/p>\n<p>\u7b80\u5355\u6765\u8bf4\uff0cHashMap\u7531\u6570\u7ec4+\u94fe\u8868\u7ec4\u6210\u7684\uff0c\u6570\u7ec4\u662fHashMap\u7684\u4e3b\u4f53\uff0c\u94fe\u8868\u5219\u662f\u4e3b\u8981\u4e3a\u4e86\u89e3\u51b3\u54c8\u5e0c\u51b2\u7a81\u800c\u5b58\u5728\u7684\uff0c\u5982\u679c\u5b9a\u4f4d\u5230\u7684\u6570\u7ec4\u4f4d\u7f6e\u4e0d\u542b\u94fe\u8868\uff08\u5f53\u524dentry\u7684next\u6307\u5411null\uff09,\u90a3\u4e48\u5bf9\u4e8e\u67e5\u627e\uff0c\u6dfb\u52a0\u7b49\u64cd\u4f5c\u5f88\u5feb\uff0c\u4ec5\u9700\u4e00\u6b21\u5bfb\u5740\u5373\u53ef\uff1b\u5982\u679c\u5b9a\u4f4d\u5230\u7684\u6570\u7ec4\u5305\u542b\u94fe\u8868\uff0c\u5bf9\u4e8e\u6dfb\u52a0\u64cd\u4f5c\uff0c\u5176\u65f6\u95f4\u590d\u6742\u5ea6\u4f9d\u7136\u4e3aO(1)\uff0c\u56e0\u4e3a\u6700\u65b0\u7684Entry\u4f1a\u63d2\u5165\u94fe\u8868\u5934\u90e8\uff0c\u6025\u9700\u8981\u7b80\u5355\u6539\u53d8\u5f15\u7528\u94fe\u5373\u53ef\uff0c\u800c\u5bf9\u4e8e\u67e5\u627e\u64cd\u4f5c\u6765\u8bb2\uff0c\u6b64\u65f6\u5c31\u9700\u8981\u904d\u5386\u94fe\u8868\uff0c\u7136\u540e\u901a\u8fc7key\u5bf9\u8c61\u7684equals\u65b9\u6cd5\u9010\u4e00\u6bd4\u5bf9\u67e5\u627e\u3002\u6240\u4ee5\uff0c\u6027\u80fd\u8003\u8651\uff0cHashMap\u4e2d\u7684\u94fe\u8868\u51fa\u73b0\u8d8a\u5c11\uff0c\u6027\u80fd\u624d\u4f1a\u8d8a\u597d\u3002<\/p>\n<p>\u5176\u4ed6\u51e0\u4e2a\u91cd\u8981\u5b57\u6bb5<\/p>\n<div class=\"cnblogs_code\">\n<div class=\"cnblogs_code_toolbar\"><span class=\"cnblogs_code_copy\"><a title=\"\u590d\u5236\u4ee3\u7801\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" src=\"http:\/\/common.cnblogs.com\/images\/copycode.gif\" alt=\"\u590d\u5236\u4ee3\u7801\" \/><\/a><\/span><\/div>\n<pre>\/\/\u5b9e\u9645\u5b58\u50a8\u7684key-value\u952e\u503c\u5bf9\u7684\u4e2a\u6570\ntransient int size;\n\/\/\u9608\u503c\uff0c\u5f53table == {}\u65f6\uff0c\u8be5\u503c\u4e3a\u521d\u59cb\u5bb9\u91cf\uff08\u521d\u59cb\u5bb9\u91cf\u9ed8\u8ba4\u4e3a16\uff09\uff1b\u5f53table\u88ab\u586b\u5145\u4e86\uff0c\u4e5f\u5c31\u662f\u4e3atable\u5206\u914d\u5185\u5b58\u7a7a\u95f4\u540e\uff0cthreshold\u4e00\u822c\u4e3a capacity*loadFactory\u3002HashMap\u5728\u8fdb\u884c\u6269\u5bb9\u65f6\u9700\u8981\u53c2\u8003threshold\uff0c\u540e\u9762\u4f1a\u8be6\u7ec6\u8c08\u5230\nint threshold;\n\/\/\u8d1f\u8f7d\u56e0\u5b50\uff0c\u4ee3\u8868\u4e86table\u7684\u586b\u5145\u5ea6\u6709\u591a\u5c11\uff0c\u9ed8\u8ba4\u662f0.75\nfinal float loadFactor;\n\/\/\u7528\u4e8e\u5feb\u901f\u5931\u8d25\uff0c\u7531\u4e8eHashMap\u975e\u7ebf\u7a0b\u5b89\u5168\uff0c\u5728\u5bf9HashMap\u8fdb\u884c\u8fed\u4ee3\u65f6\uff0c\u5982\u679c\u671f\u95f4\u5176\u4ed6\u7ebf\u7a0b\u7684\u53c2\u4e0e\u5bfc\u81f4HashMap\u7684\u7ed3\u6784\u53d1\u751f\u53d8\u5316\u4e86\uff08\u6bd4\u5982put\uff0cremove\u7b49\u64cd\u4f5c\uff09\uff0c\u9700\u8981\u629b\u51fa\u5f02\u5e38ConcurrentModificationException\ntransient int modCount;<\/pre>\n<div class=\"cnblogs_code_toolbar\"><span class=\"cnblogs_code_copy\"><a title=\"\u590d\u5236\u4ee3\u7801\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" src=\"http:\/\/common.cnblogs.com\/images\/copycode.gif\" alt=\"\u590d\u5236\u4ee3\u7801\" \/><\/a><\/span><\/div>\n<\/div>\n<p>HashMap\u67094\u4e2a\u6784\u9020\u5668\uff0c\u5176\u4ed6\u6784\u9020\u5668\u5982\u679c\u7528\u6237\u6ca1\u6709\u4f20\u5165initialCapacity \u548cloadFactor\u8fd9\u4e24\u4e2a\u53c2\u6570\uff0c\u4f1a\u4f7f\u7528\u9ed8\u8ba4\u503c<\/p>\n<p>initialCapacity\u9ed8\u8ba4\u4e3a16\uff0cloadFactory\u9ed8\u8ba4\u4e3a0.75<\/p>\n<p>\u6211\u4eec\u770b\u4e0b\u5176\u4e2d\u4e00\u4e2a<\/p>\n<div class=\"cnblogs_code\">\n<div class=\"cnblogs_code_toolbar\"><span class=\"cnblogs_code_copy\"><a title=\"\u590d\u5236\u4ee3\u7801\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" src=\"http:\/\/common.cnblogs.com\/images\/copycode.gif\" alt=\"\u590d\u5236\u4ee3\u7801\" \/><\/a><\/span><\/div>\n<pre>public HashMap(int initialCapacity, float loadFactor) {\n\u3000\u3000\u3000\u3000\u3000\/\/\u6b64\u5904\u5bf9\u4f20\u5165\u7684\u521d\u59cb\u5bb9\u91cf\u8fdb\u884c\u6821\u9a8c\uff0c\u6700\u5927\u4e0d\u80fd\u8d85\u8fc7MAXIMUM_CAPACITY = 1&lt;&lt;30(2<sup>30<\/sup>)\n        if (initialCapacity &lt; 0)\n            throw new IllegalArgumentException(\"Illegal initial capacity: \" +\n                                               initialCapacity);\n        if (initialCapacity &gt; MAXIMUM_CAPACITY)\n            initialCapacity = MAXIMUM_CAPACITY;\n        if (loadFactor &lt;= 0 || Float.isNaN(loadFactor))\n            throw new IllegalArgumentException(\"Illegal load factor: \" +\n                                               loadFactor);\n\n        this.loadFactor = loadFactor;\n        threshold = initialCapacity;\n\u3000\u3000\u3000\u3000\u3000\n        init();\/\/init\u65b9\u6cd5\u5728HashMap\u4e2d\u6ca1\u6709\u5b9e\u9645\u5b9e\u73b0\uff0c\u4e0d\u8fc7\u5728\u5176\u5b50\u7c7b\u5982 linkedHashMap\u4e2d\u5c31\u4f1a\u6709\u5bf9\u5e94\u5b9e\u73b0\n    }<\/pre>\n<div class=\"cnblogs_code_toolbar\"><span class=\"cnblogs_code_copy\"><a title=\"\u590d\u5236\u4ee3\u7801\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" src=\"http:\/\/common.cnblogs.com\/images\/copycode.gif\" alt=\"\u590d\u5236\u4ee3\u7801\" \/><\/a><\/span><\/div>\n<\/div>\n<p>\u4ece\u4e0a\u9762\u8fd9\u6bb5\u4ee3\u7801\u6211\u4eec\u53ef\u4ee5\u770b\u51fa\uff0c\u5728\u5e38\u89c4\u6784\u9020\u5668\u4e2d\uff0c\u6ca1\u6709\u4e3a\u6570\u7ec4table\u5206\u914d\u5185\u5b58\u7a7a\u95f4\uff08\u6709\u4e00\u4e2a\u5165\u53c2\u4e3a\u6307\u5b9aMap\u7684\u6784\u9020\u5668\u4f8b\u5916\uff09\uff0c\u800c\u662f\u5728\u6267\u884cput\u64cd\u4f5c\u7684\u65f6\u5019\u624d\u771f\u6b63\u6784\u5efatable\u6570\u7ec4<\/p>\n<p>OK,\u63a5\u4e0b\u6765\u6211\u4eec\u6765\u770b\u770bput\u64cd\u4f5c\u7684\u5b9e\u73b0\u5427<\/p>\n<div class=\"cnblogs_code\">\n<div class=\"cnblogs_code_toolbar\"><span class=\"cnblogs_code_copy\"><a title=\"\u590d\u5236\u4ee3\u7801\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" src=\"http:\/\/common.cnblogs.com\/images\/copycode.gif\" alt=\"\u590d\u5236\u4ee3\u7801\" \/><\/a><\/span><\/div>\n<pre>    public V put(K key, V value) {\n        \/\/\u5982\u679ctable\u6570\u7ec4\u4e3a\u7a7a\u6570\u7ec4{}\uff0c\u8fdb\u884c\u6570\u7ec4\u586b\u5145\uff08\u4e3atable\u5206\u914d\u5b9e\u9645\u5185\u5b58\u7a7a\u95f4\uff09\uff0c\u5165\u53c2\u4e3athreshold\uff0c\u6b64\u65f6threshold\u4e3ainitialCapacity \u9ed8\u8ba4\u662f1&lt;&lt;4(2<sup>4<\/sup>=16)\n        if (table == EMPTY_TABLE) {\n            inflateTable(threshold);\n        }\n       \/\/\u5982\u679ckey\u4e3anull\uff0c\u5b58\u50a8\u4f4d\u7f6e\u4e3atable[0]\u6216table[0]\u7684\u51b2\u7a81\u94fe\u4e0a\n        if (key == null)\n            return putForNullKey(value);\n        int hash = hash(key);\/\/\u5bf9key\u7684hashcode\u8fdb\u4e00\u6b65\u8ba1\u7b97\uff0c\u786e\u4fdd\u6563\u5217\u5747\u5300\n        int i = indexFor(hash, table.length);\/\/\u83b7\u53d6\u5728table\u4e2d\u7684\u5b9e\u9645\u4f4d\u7f6e\n        for (Entry&lt;K,V&gt; e = table[i]; e != null; e = e.next) {\n        \/\/\u5982\u679c\u8be5\u5bf9\u5e94\u6570\u636e\u5df2\u5b58\u5728\uff0c\u6267\u884c\u8986\u76d6\u64cd\u4f5c\u3002\u7528\u65b0value\u66ff\u6362\u65e7value\uff0c\u5e76\u8fd4\u56de\u65e7value\n            Object k;\n            if (e.hash == hash &amp;&amp; ((k = e.key) == key || key.equals(k))) {\n                V oldValue = e.value;\n                e.value = value;\n                e.recordAccess(this);\n                return oldValue;\n            }\n        }\n        modCount++;\/\/\u4fdd\u8bc1\u5e76\u53d1\u8bbf\u95ee\u65f6\uff0c\u82e5HashMap\u5185\u90e8\u7ed3\u6784\u53d1\u751f\u53d8\u5316\uff0c\u5feb\u901f\u54cd\u5e94\u5931\u8d25\n        addEntry(hash, key, value, i);\/\/\u65b0\u589e\u4e00\u4e2aentry\n        return null;\n    }<\/pre>\n<div class=\"cnblogs_code_toolbar\"><span class=\"cnblogs_code_copy\"><a title=\"\u590d\u5236\u4ee3\u7801\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" src=\"http:\/\/common.cnblogs.com\/images\/copycode.gif\" alt=\"\u590d\u5236\u4ee3\u7801\" \/><\/a><\/span><\/div>\n<\/div>\n<p>\u5148\u6765\u770b\u770binflateTable\u8fd9\u4e2a\u65b9\u6cd5<\/p>\n<div class=\"cnblogs_code\">\n<div class=\"cnblogs_code_toolbar\"><span class=\"cnblogs_code_copy\"><a title=\"\u590d\u5236\u4ee3\u7801\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" src=\"http:\/\/common.cnblogs.com\/images\/copycode.gif\" alt=\"\u590d\u5236\u4ee3\u7801\" \/><\/a><\/span><\/div>\n<pre>private void inflateTable(int toSize) {\n        int capacity = roundUpToPowerOf2(toSize);\/\/capacity\u4e00\u5b9a\u662f2\u7684\u6b21\u5e42\n        threshold = (int) Math.min(capacity * loadFactor, MAXIMUM_CAPACITY + 1);\/\/\u6b64\u5904\u4e3athreshold\u8d4b\u503c\uff0c\u53d6capacity*loadFactor\u548cMAXIMUM_CAPACITY+1\u7684\u6700\u5c0f\u503c\uff0ccapaticy\u4e00\u5b9a\u4e0d\u4f1a\u8d85\u8fc7MAXIMUM_CAPACITY\uff0c\u9664\u975eloadFactor\u5927\u4e8e1\n        table = new Entry[capacity];\n        initHashSeedAsNeeded(capacity);\n    }<\/pre>\n<div class=\"cnblogs_code_toolbar\"><span class=\"cnblogs_code_copy\"><a title=\"\u590d\u5236\u4ee3\u7801\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" src=\"http:\/\/common.cnblogs.com\/images\/copycode.gif\" alt=\"\u590d\u5236\u4ee3\u7801\" \/><\/a><\/span><\/div>\n<\/div>\n<p>inflateTable\u8fd9\u4e2a\u65b9\u6cd5\u7528\u4e8e\u4e3a\u4e3b\u5e72\u6570\u7ec4table\u5728\u5185\u5b58\u4e2d\u5206\u914d\u5b58\u50a8\u7a7a\u95f4\uff0c\u901a\u8fc7roundUpToPowerOf2(toSize)\u53ef\u4ee5\u786e\u4fddcapacity\u4e3a\u5927\u4e8e\u6216\u7b49\u4e8etoSize\u7684\u6700\u63a5\u8fd1toSize\u7684\u4e8c\u6b21\u5e42\uff0c\u6bd4\u5982toSize=13,\u5219capacity=16;to_size=16,capacity=16;to_size=17,capacity=32.<\/p>\n<div class=\"cnblogs_code\">\n<div class=\"cnblogs_code_toolbar\"><span class=\"cnblogs_code_copy\"><a title=\"\u590d\u5236\u4ee3\u7801\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" src=\"http:\/\/common.cnblogs.com\/images\/copycode.gif\" alt=\"\u590d\u5236\u4ee3\u7801\" \/><\/a><\/span><\/div>\n<pre> private static int roundUpToPowerOf2(int number) {\n        \/\/ assert number &gt;= 0 : \"number must be non-negative\";\n        return number &gt;= MAXIMUM_CAPACITY\n                ? MAXIMUM_CAPACITY\n                : (number &gt; 1) ? Integer.highestOneBit((number - 1) &lt;&lt; 1) : 1;\n    }<\/pre>\n<div class=\"cnblogs_code_toolbar\"><span class=\"cnblogs_code_copy\"><a title=\"\u590d\u5236\u4ee3\u7801\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" src=\"http:\/\/common.cnblogs.com\/images\/copycode.gif\" alt=\"\u590d\u5236\u4ee3\u7801\" \/><\/a><\/span><\/div>\n<\/div>\n<p>roundUpToPowerOf2\u4e2d\u7684\u8fd9\u6bb5\u5904\u7406\u4f7f\u5f97\u6570\u7ec4\u957f\u5ea6\u4e00\u5b9a\u4e3a2\u7684\u6b21\u5e42\uff0cInteger.highestOneBit\u662f\u7528\u6765\u83b7\u53d6\u6700\u5de6\u8fb9\u7684bit\uff08\u5176\u4ed6bit\u4f4d\u4e3a0\uff09\u6240\u4ee3\u8868\u7684\u6570\u503c.<\/p>\n<p>hash\u51fd\u6570<\/p>\n<div class=\"cnblogs_code\">\n<div class=\"cnblogs_code_toolbar\"><span class=\"cnblogs_code_copy\"><a title=\"\u590d\u5236\u4ee3\u7801\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" src=\"http:\/\/common.cnblogs.com\/images\/copycode.gif\" alt=\"\u590d\u5236\u4ee3\u7801\" \/><\/a><\/span><\/div>\n<pre>\/\/\u8fd9\u662f\u4e00\u4e2a\u795e\u5947\u7684\u51fd\u6570\uff0c\u7528\u4e86\u5f88\u591a\u7684\u5f02\u6216\uff0c\u79fb\u4f4d\u7b49\u8fd0\u7b97\uff0c\u5bf9key\u7684hashcode\u8fdb\u4e00\u6b65\u8fdb\u884c\u8ba1\u7b97\u4ee5\u53ca\u4e8c\u8fdb\u5236\u4f4d\u7684\u8c03\u6574\u7b49\u6765\u4fdd\u8bc1\u6700\u7ec8\u83b7\u53d6\u7684\u5b58\u50a8\u4f4d\u7f6e\u5c3d\u91cf\u5206\u5e03\u5747\u5300\nfinal int hash(Object k) {\n        int h = hashSeed;\n        if (0 != h &amp;&amp; k instanceof String) {\n            return sun.misc.Hashing.stringHash32((String) k);\n        }\n\n        h ^= k.hashCode();\n\n        h ^= (h &gt;&gt;&gt; 20) ^ (h &gt;&gt;&gt; 12);\n        return h ^ (h &gt;&gt;&gt; 7) ^ (h &gt;&gt;&gt; 4);\n    }<\/pre>\n<div class=\"cnblogs_code_toolbar\"><span class=\"cnblogs_code_copy\"><a title=\"\u590d\u5236\u4ee3\u7801\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" src=\"http:\/\/common.cnblogs.com\/images\/copycode.gif\" alt=\"\u590d\u5236\u4ee3\u7801\" \/><\/a><\/span><\/div>\n<\/div>\n<p>\u4ee5\u4e0ahash\u51fd\u6570\u8ba1\u7b97\u51fa\u7684\u503c\uff0c\u901a\u8fc7indexFor\u8fdb\u4e00\u6b65\u5904\u7406\u6765\u83b7\u53d6\u5b9e\u9645\u7684\u5b58\u50a8\u4f4d\u7f6e<\/p>\n<div class=\"cnblogs_code\">\n<div class=\"cnblogs_code_toolbar\"><span class=\"cnblogs_code_copy\"><a title=\"\u590d\u5236\u4ee3\u7801\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" src=\"http:\/\/common.cnblogs.com\/images\/copycode.gif\" alt=\"\u590d\u5236\u4ee3\u7801\" \/><\/a><\/span><\/div>\n<pre>\u3000\u3000\/**\n     * \u8fd4\u56de\u6570\u7ec4\u4e0b\u6807\n     *\/\n    static int indexFor(int h, int length) {\n        return h &amp; (length-1);\n    }<\/pre>\n<div class=\"cnblogs_code_toolbar\"><span class=\"cnblogs_code_copy\"><a title=\"\u590d\u5236\u4ee3\u7801\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" src=\"http:\/\/common.cnblogs.com\/images\/copycode.gif\" alt=\"\u590d\u5236\u4ee3\u7801\" \/><\/a><\/span><\/div>\n<\/div>\n<p>h&amp;\uff08length-1\uff09\u4fdd\u8bc1\u83b7\u53d6\u7684index\u4e00\u5b9a\u5728\u6570\u7ec4\u8303\u56f4\u5185\uff0c\u4e3e\u4e2a\u4f8b\u5b50\uff0c\u9ed8\u8ba4\u5bb9\u91cf16\uff0clength-1=15\uff0ch=18,\u8f6c\u6362\u6210\u4e8c\u8fdb\u5236\u8ba1\u7b97\u4e3a<\/p>\n<div class=\"cnblogs_code\">\n<pre>        1  0  0  1  0\n    &amp;   0  1  1  1  1\n    __________________\n        0  0  0  1  0    = 2<\/pre>\n<\/div>\n<p>\u6700\u7ec8\u8ba1\u7b97\u51fa\u7684index=2\u3002\u6709\u4e9b\u7248\u672c\u7684\u5bf9\u4e8e\u6b64\u5904\u7684\u8ba1\u7b97\u4f1a\u4f7f\u7528 \u53d6\u6a21\u8fd0\u7b97\uff0c\u4e5f\u80fd\u4fdd\u8bc1index\u4e00\u5b9a\u5728\u6570\u7ec4\u8303\u56f4\u5185\uff0c\u4e0d\u8fc7\u4f4d\u8fd0\u7b97\u5bf9\u8ba1\u7b97\u673a\u6765\u8bf4\uff0c\u6027\u80fd\u66f4\u9ad8\u4e00\u4e9b\uff08HashMap\u4e2d\u6709\u5927\u91cf\u4f4d\u8fd0\u7b97\uff09<\/p>\n<p>\u6240\u4ee5\u6700\u7ec8\u5b58\u50a8\u4f4d\u7f6e\u7684\u786e\u5b9a\u6d41\u7a0b\u662f\u8fd9\u6837\u7684\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/images2015.cnblogs.com\/blog\/1024555\/201611\/1024555-20161115133556388-1098209938.png\" alt=\"\" width=\"753\" height=\"74\" \/><\/p>\n<p>\u518d\u6765\u770b\u770baddEntry\u7684\u5b9e\u73b0\uff1a<\/p>\n<div class=\"cnblogs_code\">\n<div class=\"cnblogs_code_toolbar\"><span class=\"cnblogs_code_copy\"><a title=\"\u590d\u5236\u4ee3\u7801\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" src=\"http:\/\/common.cnblogs.com\/images\/copycode.gif\" alt=\"\u590d\u5236\u4ee3\u7801\" \/><\/a><\/span><\/div>\n<pre>void addEntry(int hash, K key, V value, int bucketIndex) {\n        if ((size &gt;= threshold) &amp;&amp; (null != table[bucketIndex])) {\n            resize(2 * table.length);\/\/\u5f53size\u8d85\u8fc7\u4e34\u754c\u9608\u503cthreshold\uff0c\u5e76\u4e14\u5373\u5c06\u53d1\u751f\u54c8\u5e0c\u51b2\u7a81\u65f6\u8fdb\u884c\u6269\u5bb9\n            hash = (null != key) ? hash(key) : 0;\n            bucketIndex = indexFor(hash, table.length);\n        }\n\n        createEntry(hash, key, value, bucketIndex);\n    }<\/pre>\n<div class=\"cnblogs_code_toolbar\"><span class=\"cnblogs_code_copy\"><a title=\"\u590d\u5236\u4ee3\u7801\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" src=\"http:\/\/common.cnblogs.com\/images\/copycode.gif\" alt=\"\u590d\u5236\u4ee3\u7801\" \/><\/a><\/span><\/div>\n<\/div>\n<p>\u901a\u8fc7\u4ee5\u4e0a\u4ee3\u7801\u80fd\u591f\u5f97\u77e5\uff0c\u5f53\u53d1\u751f\u54c8\u5e0c\u51b2\u7a81\u5e76\u4e14size\u5927\u4e8e\u9608\u503c\u7684\u65f6\u5019\uff0c\u9700\u8981\u8fdb\u884c\u6570\u7ec4\u6269\u5bb9\uff0c\u6269\u5bb9\u65f6\uff0c\u9700\u8981\u65b0\u5efa\u4e00\u4e2a\u957f\u5ea6\u4e3a\u4e4b\u524d\u6570\u7ec42\u500d\u7684\u65b0\u7684\u6570\u7ec4\uff0c\u7136\u540e\u5c06\u5f53\u524d\u7684Entry\u6570\u7ec4\u4e2d\u7684\u5143\u7d20\u5168\u90e8\u4f20\u8f93\u8fc7\u53bb\uff0c\u6269\u5bb9\u540e\u7684\u65b0\u6570\u7ec4\u957f\u5ea6\u4e3a\u4e4b\u524d\u76842\u500d\uff0c\u6240\u4ee5\u6269\u5bb9\u76f8\u5bf9\u6765\u8bf4\u662f\u4e2a\u8017\u8d44\u6e90\u7684\u64cd\u4f5c\u3002<\/p>\n<h1><a name=\"t2\"><\/a><a target=\"_blank\" name=\"t3\" rel=\"noopener noreferrer\"><\/a>\u4e09\u3001\u4e3a\u4f55HashMap\u7684\u6570\u7ec4\u957f\u5ea6\u4e00\u5b9a\u662f2\u7684\u6b21\u5e42\uff1f<\/h1>\n<p>\u6211\u4eec\u6765\u7ee7\u7eed\u770b\u4e0a\u9762\u63d0\u5230\u7684resize\u65b9\u6cd5<\/p>\n<div class=\"cnblogs_code\">\n<div class=\"cnblogs_code_toolbar\"><span class=\"cnblogs_code_copy\"><a title=\"\u590d\u5236\u4ee3\u7801\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" src=\"http:\/\/common.cnblogs.com\/images\/copycode.gif\" alt=\"\u590d\u5236\u4ee3\u7801\" \/><\/a><\/span><\/div>\n<pre> void resize(int newCapacity) {\n        Entry[] oldTable = table;\n        int oldCapacity = oldTable.length;\n        if (oldCapacity == MAXIMUM_CAPACITY) {\n            threshold = Integer.MAX_VALUE;\n            return;\n        }\n\n        Entry[] newTable = new Entry[newCapacity];\n        transfer(newTable, initHashSeedAsNeeded(newCapacity));\n        table = newTable;\n        threshold = (int)Math.min(newCapacity * loadFactor, MAXIMUM_CAPACITY + 1);\n    }<\/pre>\n<div class=\"cnblogs_code_toolbar\"><span class=\"cnblogs_code_copy\"><a title=\"\u590d\u5236\u4ee3\u7801\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" src=\"http:\/\/common.cnblogs.com\/images\/copycode.gif\" alt=\"\u590d\u5236\u4ee3\u7801\" \/><\/a><\/span><\/div>\n<\/div>\n<p>\u5982\u679c\u6570\u7ec4\u8fdb\u884c\u6269\u5bb9\uff0c\u6570\u7ec4\u957f\u5ea6\u53d1\u751f\u53d8\u5316\uff0c\u800c\u5b58\u50a8\u4f4d\u7f6e index = h&amp;(length-1),index\u4e5f\u53ef\u80fd\u4f1a\u53d1\u751f\u53d8\u5316\uff0c\u9700\u8981\u91cd\u65b0\u8ba1\u7b97index\uff0c\u6211\u4eec\u5148\u6765\u770b\u770btransfer\u8fd9\u4e2a\u65b9\u6cd5<\/p>\n<div class=\"cnblogs_code\">\n<div class=\"cnblogs_code_toolbar\"><span class=\"cnblogs_code_copy\"><a title=\"\u590d\u5236\u4ee3\u7801\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" src=\"http:\/\/common.cnblogs.com\/images\/copycode.gif\" alt=\"\u590d\u5236\u4ee3\u7801\" \/><\/a><\/span><\/div>\n<pre>void transfer(Entry[] newTable, boolean rehash) {\n        int newCapacity = newTable.length;\n\u3000\u3000\u3000\u3000\u3000\/\/for\u5faa\u73af\u4e2d\u7684\u4ee3\u7801\uff0c\u9010\u4e2a\u904d\u5386\u94fe\u8868\uff0c\u91cd\u65b0\u8ba1\u7b97\u7d22\u5f15\u4f4d\u7f6e\uff0c\u5c06\u8001\u6570\u7ec4\u6570\u636e\u590d\u5236\u5230\u65b0\u6570\u7ec4\u4e2d\u53bb\uff08\u6570\u7ec4\u4e0d\u5b58\u50a8\u5b9e\u9645\u6570\u636e\uff0c\u6240\u4ee5\u4ec5\u4ec5\u662f\u62f7\u8d1d\u5f15\u7528\u800c\u5df2\uff09\n        for (Entry&lt;K,V&gt; e : table) {\n            while(null != e) {\n                Entry&lt;K,V&gt; next = e.next;\n                if (rehash) {\n                    e.hash = null == e.key ? 0 : hash(e.key);\n                }\n                int i = indexFor(e.hash, newCapacity);\n\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000 \/\/\u5c06\u5f53\u524dentry\u7684next\u94fe\u6307\u5411\u65b0\u7684\u7d22\u5f15\u4f4d\u7f6e,newTable[i]\u6709\u53ef\u80fd\u4e3a\u7a7a\uff0c\u6709\u53ef\u80fd\u4e5f\u662f\u4e2aentry\u94fe\uff0c\u5982\u679c\u662fentry\u94fe\uff0c\u76f4\u63a5\u5728\u94fe\u8868\u5934\u90e8\u63d2\u5165\u3002\n                e.next = newTable[i];\n                newTable[i] = e;\n                e = next;\n            }\n        }\n    }<\/pre>\n<div class=\"cnblogs_code_toolbar\"><span class=\"cnblogs_code_copy\"><a title=\"\u590d\u5236\u4ee3\u7801\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" src=\"http:\/\/common.cnblogs.com\/images\/copycode.gif\" alt=\"\u590d\u5236\u4ee3\u7801\" \/><\/a><\/span><\/div>\n<\/div>\n<p>\u8fd9\u4e2a\u65b9\u6cd5\u5c06\u8001\u6570\u7ec4\u4e2d\u7684\u6570\u636e\u9010\u4e2a\u94fe\u8868\u5730\u904d\u5386\uff0c\u6254\u5230\u65b0\u7684\u6269\u5bb9\u540e\u7684\u6570\u7ec4\u4e2d\uff0c\u6211\u4eec\u7684\u6570\u7ec4\u7d22\u5f15\u4f4d\u7f6e\u7684\u8ba1\u7b97\u662f\u901a\u8fc7 \u5bf9key\u503c\u7684hashcode\u8fdb\u884chash\u6270\u4e71\u8fd0\u7b97\u540e\uff0c\u518d\u901a\u8fc7\u548c length-1\u8fdb\u884c\u4f4d\u8fd0\u7b97\u5f97\u5230\u6700\u7ec8\u6570\u7ec4\u7d22\u5f15\u4f4d\u7f6e\u3002<\/p>\n<p>hashMap\u7684\u6570\u7ec4\u957f\u5ea6\u4e00\u5b9a\u4fdd\u63012\u7684\u6b21\u5e42\uff0c\u6bd4\u598216\u7684\u4e8c\u8fdb\u5236\u8868\u793a\u4e3a 10000\uff0c\u90a3\u4e48length-1\u5c31\u662f15\uff0c\u4e8c\u8fdb\u5236\u4e3a01111\uff0c\u540c\u7406\u6269\u5bb9\u540e\u7684\u6570\u7ec4\u957f\u5ea6\u4e3a32\uff0c\u4e8c\u8fdb\u5236\u8868\u793a\u4e3a100000\uff0clength-1\u4e3a31\uff0c\u4e8c\u8fdb\u5236\u8868\u793a\u4e3a011111\u3002\u4ece\u4e0b\u56fe\u53ef\u4ee5\u6211\u4eec\u4e5f\u80fd\u770b\u5230\u8fd9\u6837\u4f1a\u4fdd\u8bc1\u4f4e\u4f4d\u5168\u4e3a1\uff0c\u800c\u6269\u5bb9\u540e\u53ea\u6709\u4e00\u4f4d\u5dee\u5f02\uff0c\u4e5f\u5c31\u662f\u591a\u51fa\u4e86\u6700\u5de6\u4f4d\u76841\uff0c\u8fd9\u6837\u5728\u901a\u8fc7 h&amp;(length-1)\u7684\u65f6\u5019\uff0c\u53ea\u8981h\u5bf9\u5e94\u7684\u6700\u5de6\u8fb9\u7684\u90a3\u4e00\u4e2a\u5dee\u5f02\u4f4d\u4e3a0\uff0c\u5c31\u80fd\u4fdd\u8bc1\u5f97\u5230\u7684\u65b0\u7684\u6570\u7ec4\u7d22\u5f15\u548c\u8001\u6570\u7ec4\u7d22\u5f15\u4e00\u81f4(\u5927\u5927\u51cf\u5c11\u4e86\u4e4b\u524d\u5df2\u7ecf\u6563\u5217\u826f\u597d\u7684\u8001\u6570\u7ec4\u7684\u6570\u636e\u4f4d\u7f6e\u91cd\u65b0\u8c03\u6362)\uff0c\u4e2a\u4eba\u7406\u89e3\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/images2015.cnblogs.com\/blog\/1024555\/201611\/1024555-20161115215812138-679881037.png\" alt=\"\" width=\"438\" height=\"194\" \/><\/p>\n<p>\u8fd8\u6709\uff0c\u6570\u7ec4\u957f\u5ea6\u4fdd\u63012\u7684\u6b21\u5e42\uff0clength-1\u7684\u4f4e\u4f4d\u90fd\u4e3a1\uff0c\u4f1a\u4f7f\u5f97\u83b7\u5f97\u7684\u6570\u7ec4\u7d22\u5f15index\u66f4\u52a0\u5747\u5300\uff0c\u6bd4\u5982\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/images2015.cnblogs.com\/blog\/1024555\/201611\/1024555-20161116001404732-625340289.png\" alt=\"\" width=\"541\" height=\"244\" \/><\/p>\n<p>\u6211\u4eec\u770b\u5230\uff0c\u4e0a\u9762\u7684&amp;\u8fd0\u7b97\uff0c\u9ad8\u4f4d\u662f\u4e0d\u4f1a\u5bf9\u7ed3\u679c\u4ea7\u751f\u5f71\u54cd\u7684\uff08hash\u51fd\u6570\u91c7\u7528\u5404\u79cd\u4f4d\u8fd0\u7b97\u53ef\u80fd\u4e5f\u662f\u4e3a\u4e86\u4f7f\u5f97\u4f4e\u4f4d\u66f4\u52a0\u6563\u5217\uff09\uff0c\u6211\u4eec\u53ea\u5173\u6ce8\u4f4e\u4f4dbit\uff0c\u5982\u679c\u4f4e\u4f4d\u5168\u90e8\u4e3a1\uff0c\u90a3\u4e48\u5bf9\u4e8eh\u4f4e\u4f4d\u90e8\u5206\u6765\u8bf4\uff0c\u4efb\u4f55\u4e00\u4f4d\u7684\u53d8\u5316\u90fd\u4f1a\u5bf9\u7ed3\u679c\u4ea7\u751f\u5f71\u54cd\uff0c\u4e5f\u5c31\u662f\u8bf4\uff0c\u8981\u5f97\u5230index=21\u8fd9\u4e2a\u5b58\u50a8\u4f4d\u7f6e\uff0ch\u7684\u4f4e\u4f4d\u53ea\u6709\u8fd9\u4e00\u79cd\u7ec4\u5408\u3002\u8fd9\u4e5f\u662f\u6570\u7ec4\u957f\u5ea6\u8bbe\u8ba1\u4e3a\u5fc5\u987b\u4e3a2\u7684\u6b21\u5e42\u7684\u539f\u56e0\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/images2015.cnblogs.com\/blog\/1024555\/201611\/1024555-20161116001717560-1455096254.png\" alt=\"\" width=\"643\" height=\"231\" \/><\/p>\n<p>\u5982\u679c\u4e0d\u662f2\u7684\u6b21\u5e42\uff0c\u4e5f\u5c31\u662f\u4f4e\u4f4d\u4e0d\u662f\u5168\u4e3a1\u6b64\u65f6\uff0c\u8981\u4f7f\u5f97index=21\uff0ch\u7684\u4f4e\u4f4d\u90e8\u5206\u4e0d\u518d\u5177\u6709\u552f\u4e00\u6027\u4e86\uff0c\u54c8\u5e0c\u51b2\u7a81\u7684\u51e0\u7387\u4f1a\u53d8\u7684\u66f4\u5927\uff0c\u540c\u65f6\uff0cindex\u5bf9\u5e94\u7684\u8fd9\u4e2abit\u4f4d<a href=\"https:\/\/www.baidu.com\/s?wd=%E6%97%A0%E8%AE%BA%E5%A6%82%E4%BD%95&amp;tn=24004469_oem_dg&amp;rsv_dl=gh_pl_sl_csd\" target=\"_blank\" rel=\"noopener noreferrer\">\u65e0\u8bba\u5982\u4f55<\/a>\u4e0d\u4f1a\u7b49\u4e8e1\u4e86\uff0c\u800c\u5bf9\u5e94\u7684\u90a3\u4e9b\u6570\u7ec4\u4f4d\u7f6e\u4e5f\u5c31\u88ab\u767d\u767d\u6d6a\u8d39\u4e86\u3002<\/p>\n<p>get\u65b9\u6cd5<\/p>\n<div class=\"cnblogs_code\">\n<div class=\"cnblogs_code_toolbar\"><span class=\"cnblogs_code_copy\"><a title=\"\u590d\u5236\u4ee3\u7801\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" src=\"http:\/\/common.cnblogs.com\/images\/copycode.gif\" alt=\"\u590d\u5236\u4ee3\u7801\" \/><\/a><\/span><\/div>\n<pre> public V get(Object key) {\n\u3000\u3000\u3000\u3000 \/\/\u5982\u679ckey\u4e3anull,\u5219\u76f4\u63a5\u53bbtable[0]\u5904\u53bb\u68c0\u7d22\u5373\u53ef\u3002\n        if (key == null)\n            return getForNullKey();\n        Entry&lt;K,V&gt; entry = getEntry(key);\n        return null == entry ? null : entry.getValue();\n }<\/pre>\n<div class=\"cnblogs_code_toolbar\"><span class=\"cnblogs_code_copy\"><a title=\"\u590d\u5236\u4ee3\u7801\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" src=\"http:\/\/common.cnblogs.com\/images\/copycode.gif\" alt=\"\u590d\u5236\u4ee3\u7801\" \/><\/a><\/span><\/div>\n<\/div>\n<p>get\u65b9\u6cd5\u901a\u8fc7key\u503c\u8fd4\u56de\u5bf9\u5e94value\uff0c\u5982\u679ckey\u4e3anull\uff0c\u76f4\u63a5\u53bbtable[0]\u5904\u68c0\u7d22\u3002\u6211\u4eec\u518d\u770b\u4e00\u4e0bgetEntry\u8fd9\u4e2a\u65b9\u6cd5<\/p>\n<div class=\"cnblogs_code\">\n<div class=\"cnblogs_code_toolbar\"><span class=\"cnblogs_code_copy\"><a title=\"\u590d\u5236\u4ee3\u7801\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" src=\"http:\/\/common.cnblogs.com\/images\/copycode.gif\" alt=\"\u590d\u5236\u4ee3\u7801\" \/><\/a><\/span><\/div>\n<pre>final Entry&lt;K,V&gt; getEntry(Object key) {\n            \n        if (size == 0) {\n            return null;\n        }\n        \/\/\u901a\u8fc7key\u7684hashcode\u503c\u8ba1\u7b97hash\u503c\n        int hash = (key == null) ? 0 : hash(key);\n        \/\/indexFor (hash&amp;length-1) \u83b7\u53d6\u6700\u7ec8\u6570\u7ec4\u7d22\u5f15\uff0c\u7136\u540e\u904d\u5386\u94fe\u8868\uff0c\u901a\u8fc7equals\u65b9\u6cd5\u6bd4\u5bf9\u627e\u51fa\u5bf9\u5e94\u8bb0\u5f55\n        for (Entry&lt;K,V&gt; e = table[indexFor(hash, table.length)];\n             e != null;\n             e = e.next) {\n            Object k;\n            if (e.hash == hash &amp;&amp; \n                ((k = e.key) == key || (key != null &amp;&amp; key.equals(k))))\n                return e;\n        }\n        return null;\n    }<\/pre>\n<div class=\"cnblogs_code_toolbar\"><span class=\"cnblogs_code_copy\"><a title=\"\u590d\u5236\u4ee3\u7801\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" src=\"http:\/\/common.cnblogs.com\/images\/copycode.gif\" alt=\"\u590d\u5236\u4ee3\u7801\" \/><\/a><\/span><\/div>\n<\/div>\n<p>\u53ef\u4ee5\u770b\u51fa\uff0cget\u65b9\u6cd5\u7684\u5b9e\u73b0\u76f8\u5bf9\u7b80\u5355\uff0ckey(hashcode)&#8211;&gt;hash&#8211;&gt;indexFor&#8211;&gt;\u6700\u7ec8\u7d22\u5f15\u4f4d\u7f6e\uff0c\u627e\u5230\u5bf9\u5e94\u4f4d\u7f6etable[i]\uff0c\u518d\u67e5\u770b\u662f\u5426\u6709\u94fe\u8868\uff0c\u904d\u5386\u94fe\u8868\uff0c\u901a\u8fc7key\u7684equals\u65b9\u6cd5\u6bd4\u5bf9\u67e5\u627e\u5bf9\u5e94\u7684\u8bb0\u5f55\u3002\u8981\u6ce8\u610f\u7684\u662f\uff0c\u6709\u4eba\u89c9\u5f97\u4e0a\u9762\u5728\u5b9a\u4f4d\u5230\u6570\u7ec4\u4f4d\u7f6e\u4e4b\u540e\u7136\u540e\u904d\u5386\u94fe\u8868\u7684\u65f6\u5019\uff0ce.hash == hash\u8fd9\u4e2a\u5224\u65ad\u6ca1\u5fc5\u8981\uff0c\u4ec5\u901a\u8fc7equals\u5224\u65ad\u5c31\u53ef\u4ee5\u3002\u5176\u5b9e\u4e0d\u7136\uff0c\u8bd5\u60f3\u4e00\u4e0b\uff0c\u5982\u679c\u4f20\u5165\u7684key\u5bf9\u8c61\u91cd\u5199\u4e86equals\u65b9\u6cd5\u5374\u6ca1\u6709\u91cd\u5199hashCode\uff0c\u800c\u6070\u5de7\u6b64\u5bf9\u8c61\u5b9a\u4f4d\u5230\u8fd9\u4e2a\u6570\u7ec4\u4f4d\u7f6e\uff0c\u5982\u679c\u4ec5\u4ec5\u7528equals\u5224\u65ad\u53ef\u80fd\u662f\u76f8\u7b49\u7684\uff0c\u4f46\u5176hashCode\u548c\u5f53\u524d\u5bf9\u8c61\u4e0d\u4e00\u81f4\uff0c\u8fd9\u79cd\u60c5\u51b5\uff0c\u6839\u636eObject\u7684hashCode\u7684\u7ea6\u5b9a\uff0c\u4e0d\u80fd\u8fd4\u56de\u5f53\u524d\u5bf9\u8c61\uff0c\u800c\u5e94\u8be5\u8fd4\u56denull\uff0c\u540e\u9762\u7684\u4f8b\u5b50\u4f1a\u505a\u51fa\u8fdb\u4e00\u6b65\u89e3\u91ca\u3002<\/p>\n<h1><a name=\"t3\"><\/a><a target=\"_blank\" name=\"t4\" rel=\"noopener noreferrer\"><\/a>\u56db\u3001\u91cd\u5199equals\u65b9\u6cd5\u9700\u540c\u65f6\u91cd\u5199hashCode\u65b9\u6cd5<\/h1>\n<p>\u5173\u4e8eHashMap\u7684\u6e90\u7801\u5206\u6790\u5c31\u4ecb\u7ecd\u5230\u8fd9\u513f\u4e86\uff0c\u6700\u540e\u6211\u4eec\u518d\u804a\u804a<a href=\"https:\/\/www.baidu.com\/s?wd=%E8%80%81%E7%94%9F%E5%B8%B8%E8%B0%88&amp;tn=24004469_oem_dg&amp;rsv_dl=gh_pl_sl_csd\" target=\"_blank\" rel=\"noopener noreferrer\">\u8001\u751f\u5e38\u8c08<\/a>\u7684\u4e00\u4e2a\u95ee\u9898\uff0c\u5404\u79cd\u8d44\u6599\u4e0a\u90fd\u4f1a\u63d0\u5230\uff0c\u201c\u91cd\u5199equals\u65f6\u4e5f\u8981\u540c\u65f6\u8986\u76d6hashcode\u201d\uff0c\u6211\u4eec\u4e3e\u4e2a\u5c0f\u4f8b\u5b50\u6765\u770b\u770b\uff0c\u5982\u679c\u91cd\u5199\u4e86equals\u800c\u4e0d\u91cd\u5199hashcode\u4f1a\u53d1\u751f\u4ec0\u4e48\u6837\u7684\u95ee\u9898<\/p>\n<div class=\"cnblogs_code\">\n<div class=\"cnblogs_code_toolbar\"><span class=\"cnblogs_code_copy\"><a title=\"\u590d\u5236\u4ee3\u7801\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" src=\"http:\/\/common.cnblogs.com\/images\/copycode.gif\" alt=\"\u590d\u5236\u4ee3\u7801\" \/><\/a><\/span><\/div>\n<pre>\/**\n * Created by chengxiao on 2016\/11\/15.\n *\/\npublic class MyTest {\n    private static class Person{\n        int idCard;\n        String name;\n\n        public Person(int idCard, String name) {\n            this.idCard = idCard;\n            this.name = name;\n        }\n        @Override\n        public boolean equals(Object o) {\n            if (this == o) {\n                return true;\n            }\n            if (o == null || getClass() != o.getClass()){\n                return false;\n            }\n            Person person = (Person) o;\n            \/\/\u4e24\u4e2a\u5bf9\u8c61\u662f\u5426\u7b49\u503c\uff0c\u901a\u8fc7idCard\u6765\u786e\u5b9a\n            return this.idCard == person.idCard;\n        }\n\n    }\n    public static void main(String []args){\n        HashMap&lt;Person,String&gt; map = new HashMap&lt;Person, String&gt;();\n        Person person = new Person(1234,\"\u4e54\u5cf0\");\n        \/\/put\u5230hashmap\u4e2d\u53bb\n        map.put(person,\"\u5929\u9f99\u516b\u90e8\");\n        \/\/get\u53d6\u51fa\uff0c\u4ece\u903b\u8f91\u4e0a\u8bb2\u5e94\u8be5\u80fd\u8f93\u51fa\u201c\u5929\u9f99\u516b\u90e8\u201d\n        System.out.println(\"\u7ed3\u679c:\"+map.get(new Person(1234,\"\u8427\u5cf0\")));\n    }\n}<\/pre>\n<div class=\"cnblogs_code_toolbar\"><span class=\"cnblogs_code_copy\"><a title=\"\u590d\u5236\u4ee3\u7801\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" src=\"http:\/\/common.cnblogs.com\/images\/copycode.gif\" alt=\"\u590d\u5236\u4ee3\u7801\" \/><\/a><\/span><\/div>\n<\/div>\n<p>\u5b9e\u9645\u8f93\u51fa\u7ed3\u679c\uff1a<\/p>\n<div class=\"cnblogs_code\">\n<pre>\u7ed3\u679c\uff1anull<\/pre>\n<\/div>\n<p>\u5982\u679c\u6211\u4eec\u5df2\u7ecf\u5bf9HashMap\u7684\u539f\u7406\u6709\u4e86\u4e00\u5b9a\u4e86\u89e3\uff0c\u8fd9\u4e2a\u7ed3\u679c\u5c31\u4e0d\u96be\u7406\u89e3\u4e86\u3002\u5c3d\u7ba1\u6211\u4eec\u5728\u8fdb\u884cget\u548cput\u64cd\u4f5c\u7684\u65f6\u5019\uff0c\u4f7f\u7528\u7684key\u4ece\u903b\u8f91\u4e0a\u8bb2\u662f\u7b49\u503c\u7684\uff08\u901a\u8fc7equals\u6bd4\u8f83\u662f\u76f8\u7b49\u7684\uff09\uff0c\u4f46\u7531\u4e8e\u6ca1\u6709\u91cd\u5199hashCode\u65b9\u6cd5\uff0c\u6240\u4ee5put\u64cd\u4f5c\u65f6\uff0ckey(hashcode1)&#8211;&gt;hash&#8211;&gt;indexFor&#8211;&gt;\u6700\u7ec8\u7d22\u5f15\u4f4d\u7f6e \uff0c\u800c\u901a\u8fc7key\u53d6\u51favalue\u7684\u65f6\u5019 key(hashcode1)&#8211;&gt;hash&#8211;&gt;indexFor&#8211;&gt;\u6700\u7ec8\u7d22\u5f15\u4f4d\u7f6e\uff0c\u7531\u4e8ehashcode1\u4e0d\u7b49\u4e8ehashcode2\uff0c\u5bfc\u81f4\u6ca1\u6709\u5b9a\u4f4d\u5230\u4e00\u4e2a\u6570\u7ec4\u4f4d\u7f6e\u800c\u8fd4\u56de\u903b\u8f91\u4e0a\u9519\u8bef\u7684\u503cnull\uff08\u4e5f\u6709\u53ef\u80fd\u78b0\u5de7\u5b9a\u4f4d\u5230\u4e00\u4e2a\u6570\u7ec4\u4f4d\u7f6e\uff0c\u4f46\u662f\u4e5f\u4f1a\u5224\u65ad\u5176entry\u7684hash\u503c\u662f\u5426\u76f8\u7b49\uff0c\u4e0a\u9762get\u65b9\u6cd5\u4e2d\u6709\u63d0\u5230\u3002\uff09<\/p>\n<p>\u6240\u4ee5\uff0c\u5728\u91cd\u5199equals\u7684\u65b9\u6cd5\u7684\u65f6\u5019\uff0c\u5fc5\u987b\u6ce8\u610f\u91cd\u5199hashCode\u65b9\u6cd5\uff0c\u540c\u65f6\u8fd8\u8981\u4fdd\u8bc1\u901a\u8fc7equals\u5224\u65ad\u76f8\u7b49\u7684\u4e24\u4e2a\u5bf9\u8c61\uff0c\u8c03\u7528hashCode\u65b9\u6cd5\u8981\u8fd4\u56de\u540c\u6837\u7684\u6574\u6570\u503c\u3002\u800c\u5982\u679cequals\u5224\u65ad\u4e0d\u76f8\u7b49\u7684\u4e24\u4e2a\u5bf9\u8c61\uff0c\u5176hashCode\u53ef\u4ee5\u76f8\u540c\uff08\u53ea\u4e0d\u8fc7\u4f1a\u53d1\u751f\u54c8\u5e0c\u51b2\u7a81\uff0c\u5e94\u5c3d\u91cf\u907f\u514d\uff09\u3002<\/p>\n<h1><a name=\"t4\"><\/a><a target=\"_blank\" name=\"t5\" rel=\"noopener noreferrer\"><\/a>\u4e94\u3001\u603b\u7ed3<\/h1>\n<p>\u672c\u6587\u63cf\u8ff0\u4e86HashMap\u7684\u5b9e\u73b0\u539f\u7406\uff0c\u5e76\u7ed3\u5408\u6e90\u7801\u505a\u4e86\u8fdb\u4e00\u6b65\u7684\u5206\u6790\uff0c\u4e5f\u6d89\u53ca\u5230\u4e00\u4e9b\u6e90\u7801\u7ec6\u8282\u8bbe\u8ba1\u7f18\u7531\uff0c\u6700\u540e\u7b80\u5355\u4ecb\u7ecd\u4e86\u4e3a\u4ec0\u4e48\u91cd\u5199equals\u7684\u65f6\u5019\u9700\u8981\u91cd\u5199hashCode\u65b9\u6cd5\u3002\u5e0c\u671b\u672c\u7bc7\u6587\u7ae0\u80fd\u5e2e\u52a9\u5230\u5927\u5bb6\uff0c\u540c\u65f6\u4e5f\u6b22\u8fce\u8ba8\u8bba\u6307\u6b63\uff0c\u8c22\u8c22\u652f\u6301\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u54c8\u5e0c\u8868\uff08hash table\uff09\u4e5f\u53eb\u6563\u5217\u8868\uff0c\u662f\u4e00\u79cd\u975e\u5e38\u91cd\u8981\u7684\u6570\u636e\u7ed3\u6784\uff0c\u5e94\u7528\u573a\u666f\u53ca\u5176\u4e30\u5bcc\uff0c\u8bb8\u591a\u7f13\u5b58\u6280\u672f\uff08 &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"series":[],"class_list":["post-505","post","type-post","status-publish","format-standard","hentry","category-programmers"],"_links":{"self":[{"href":"https:\/\/fick707.com\/index.php?rest_route=\/wp\/v2\/posts\/505"}],"collection":[{"href":"https:\/\/fick707.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fick707.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fick707.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fick707.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=505"}],"version-history":[{"count":1,"href":"https:\/\/fick707.com\/index.php?rest_route=\/wp\/v2\/posts\/505\/revisions"}],"predecessor-version":[{"id":506,"href":"https:\/\/fick707.com\/index.php?rest_route=\/wp\/v2\/posts\/505\/revisions\/506"}],"wp:attachment":[{"href":"https:\/\/fick707.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=505"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fick707.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=505"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fick707.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=505"},{"taxonomy":"series","embeddable":true,"href":"https:\/\/fick707.com\/index.php?rest_route=%2Fwp%2Fv2%2Fseries&post=505"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}