{"id":3375,"date":"2018-11-17T09:36:42","date_gmt":"2018-11-17T01:36:42","guid":{"rendered":"http:\/\/www.xttblog.com\/?p=3375"},"modified":"2018-11-17T09:36:42","modified_gmt":"2018-11-17T01:36:42","slug":"%e6%90%9e%e4%b8%8d%e6%87%82-hashmap%ef%bc%9f%e5%8f%aa%e5%9b%a0%e4%bd%a0%e7%bc%ba%e4%b8%80%e4%b8%aa-hashmap-%e7%9a%84%e5%8e%9f%e7%90%86%e6%9c%ba%e5%88%b6%e6%b5%81%e7%a8%8b%e5%9b%be%ef%bc%81","status":"publish","type":"post","link":"https:\/\/www.xttblog.com\/?p=3375","title":{"rendered":"\u641e\u4e0d\u61c2 HashMap\uff1f\u53ea\u56e0\u4f60\u7f3a\u4e00\u4e2a HashMap \u7684\u539f\u7406\u673a\u5236\u6d41\u7a0b\u56fe\uff01"},"content":{"rendered":"<p>\n\t\u5f88\u591a\u4eba\u641e\u4e0d\u61c2 HashMap\uff0c\u6211\u8ba4\u4e3a\u7a76\u5176\u539f\u56e0\u662f\u4ed6\u4eec\u7684\u5b66\u4e60\u65b9\u6cd5\u4e0d\u5bf9\uff01\u4eca\u5929\u6211\u603b\u7ed3\u4e86\u4e00\u4e2a\u5173\u4e8e HashMap \u7684 put \u65b9\u6cd5\u6267\u884c\u8fc7\u7a0b\uff0c\u5206\u4eab\u7ed9\u5927\u5bb6\uff01\n<\/p>\n<p>\n\t\u9762\u8bd5\u7684\u65f6\u5019\uff0cHashMap \u57fa\u672c\u4e0a\u662f\u5fc5\u95ee\u7684\u77e5\u8bc6\u70b9\u3002\n<\/p>\n<p>\n\t\u5f88\u591a\u4eba\u5728\u56de\u7b54\u7684\u65f6\u5019\uff0c\u7167\u672c\u5ba3\u79d1\u3002HashMap \u6839\u636e\u952e\u7684 hashCode \u503c\u5b58\u50a8\u6570\u636e\uff0c\u5927\u591a\u6570\u60c5\u51b5\u4e0b\u53ef\u4ee5\u76f4\u63a5\u5b9a\u4f4d\u5230\u5b83\u7684\u503c\uff0c\u56e0\u800c\u5177\u6709\u5f88\u5feb\u7684\u8bbf\u95ee\u901f\u5ea6\uff0c\u4f46\u904d\u5386\u987a\u5e8f\u5374\u662f\u4e0d\u786e\u5b9a\u7684\u3002HashMap \u6700\u591a\u53ea\u5141\u8bb8\u4e00\u6761\u8bb0\u5f55\u7684\u952e\u4e3a null\uff0c\u5141\u8bb8\u591a\u6761\u8bb0\u5f55\u7684\u503c\u4e3a null\u3002HashMap \u975e\u7ebf\u7a0b\u5b89\u5168\uff0c\u5373\u4efb\u4e00\u65f6\u523b\u53ef\u4ee5\u6709\u591a\u4e2a\u7ebf\u7a0b\u540c\u65f6\u5199 HashMap\uff0c\u53ef\u80fd\u4f1a\u5bfc\u81f4\u6570\u636e\u7684\u4e0d\u4e00\u81f4\u3002\u5982\u679c\u9700\u8981\u6ee1\u8db3\u7ebf\u7a0b\u5b89\u5168\uff0c\u53ef\u4ee5\u7528 Collections \u7684synchronizedMap \u65b9\u6cd5\u4f7f HashMap \u5177\u6709\u7ebf\u7a0b\u5b89\u5168\u7684\u80fd\u529b\uff0c\u6216\u8005\u4f7f\u7528 ConcurrentHashMap\u3002\n<\/p>\n<p>\n\t\u6211\u4e00\u773c\u5c31\u80fd\u770b\u51fa\uff0c\u4ed6\u662f\u5728\u9762\u8bd5\u4e4b\u524d\u505a\u4e86\u529f\u8bfe\u3002\u5e76\u4e0d\u662f\u771f\u6b63\u7684\u61c2 HashMap\uff0c\u4e00\u4e2a put \u65b9\u6cd5\u5c31\u628a\u4ed6\u6253\u56de\u539f\u5f62\u4e86\uff01\n<\/p>\n<p>\n\t\u5b66\u4e60\u597d\u7684\u4eba\u4e3a\u4ec0\u4e48\u5b66\u4e60\u597d\uff1f\u56e0\u4e3a\u522b\u4eba\u5584\u4e8e\u603b\u7ed3\uff01\u597d\u4e86\uff0c\u5e9f\u8bdd\u4e0d\u591a\u8bf4\uff0c\u770b\u6211\u7684\u56fe\uff01\n<\/p>\n<p>\n\t<img decoding=\"async\" alt=\"HashMap put \u65b9\u6cd5\u6267\u884c\u8fc7\u7a0b\" src=\"https:\/\/raw.githubusercontent.com\/xmt1139057136\/xttblog\/master\/hashmap-put.png\" style=\"width: 1716px;height: 1360px\" \/>\u7b80\u5355\u7684\u6765\u8bf4\uff0c\u53ef\u4ee5\u7528\u4e0b\u9762\u51e0\u53e5\u8bdd\u603b\u7ed3\uff01\n<\/p>\n<p>\n\t\u2460.\u5224\u65ad\u952e\u503c\u5bf9\u6570\u7ec4 table[i] \u662f\u5426\u4e3a\u7a7a\u6216\u4e3a null\uff0c\u5426\u5219\u6267\u884c resize() \u8fdb\u884c\u6269\u5bb9\uff1b\n<\/p>\n<p>\n\t\u2461.\u6839\u636e\u952e\u503c key \u8ba1\u7b97 hash \u503c\u5f97\u5230\u63d2\u5165\u7684\u6570\u7ec4\u7d22\u5f15 i\uff0c\u5982\u679c table[i]==null\uff0c\u76f4\u63a5\u65b0\u5efa\u8282\u70b9\u6dfb\u52a0\uff0c\u8f6c\u5411\u2465\uff0c\u5982\u679c table[i] \u4e0d\u4e3a\u7a7a\uff0c\u8f6c\u5411\u2462\uff1b\n<\/p>\n<p>\n\t\u2462.\u5224\u65ad table[i] \u7684\u9996\u4e2a\u5143\u7d20\u662f\u5426\u548c key \u4e00\u6837\uff0c\u5982\u679c\u76f8\u540c\u76f4\u63a5\u8986\u76d6 value\uff0c\u5426\u5219\u8f6c\u5411\u2463\uff0c\u8fd9\u91cc\u7684\u76f8\u540c\u6307\u7684\u662f hashCode \u4ee5\u53ca equals\uff1b\n<\/p>\n<p>\n\t\u2463.\u5224\u65ad table[i] \u662f\u5426\u4e3a treeNode\uff0c\u5373&nbsp;table[i] \u662f\u5426\u662f\u7ea2\u9ed1\u6811\uff0c\u5982\u679c\u662f\u7ea2\u9ed1\u6811\uff0c\u5219\u76f4\u63a5\u5728\u6811\u4e2d\u63d2\u5165\u952e\u503c\u5bf9\uff0c\u5426\u5219\u8f6c\u5411\u2464\uff1b\n<\/p>\n<p>\n\t\u2464.\u904d\u5386 table[i]\uff0c\u5224\u65ad\u94fe\u8868\u957f\u5ea6\u662f\u5426\u5927\u4e8e8\uff0c\u5927\u4e8e8\u7684\u8bdd\u628a\u94fe\u8868\u8f6c\u6362\u4e3a\u7ea2\u9ed1\u6811\uff0c\u5728\u7ea2\u9ed1\u6811\u4e2d\u6267\u884c\u63d2\u5165\u64cd\u4f5c\uff0c\u5426\u5219\u8fdb\u884c\u94fe\u8868\u7684\u63d2\u5165\u64cd\u4f5c\uff1b\u904d\u5386\u8fc7\u7a0b\u4e2d\u82e5\u53d1\u73b0 key \u5df2\u7ecf\u5b58\u5728\u76f4\u63a5\u8986\u76d6 value \u5373\u53ef\uff1b\n<\/p>\n<p>\n\t\u2465.\u63d2\u5165\u6210\u529f\u540e\uff0c\u5224\u65ad\u5b9e\u9645\u5b58\u5728\u7684\u952e\u503c\u5bf9\u6570\u91cfsize\u662f\u5426\u8d85\u591a\u4e86\u6700\u5927\u5bb9\u91cf threshold\uff0c\u5982\u679c\u8d85\u8fc7\uff0c\u8fdb\u884c\u6269\u5bb9\u3002\n<\/p>\n<p>\n\t\u540c\u6837\u7684\uff0c\u5f53\u4f60\u628a HashMap \u7684\u5176\u4ed6\u7684\u65b9\u6cd5\u90fd\u753b\u51fa\u6d41\u7a0b\u56fe\uff0c\u4f60\u4f1a\u53d1\u73b0\u6240\u6709\u7684\u4e1c\u897f\u90fd\u662f\u90a3\u4e48\u7684\u7b80\u5355\uff01<\/p>\n<!-- <audio autoplay=\"autoplay\" height=\"100\" width=\"100\" hidden=\"true\"><source src=\"https:\/\/c.coka.la\/orAvPR.mp3\" type=\"audio\/mp3\"\/><\/audio><img decoding=\"async\" src=\"https:\/\/images.weserv.nl\/?url=https:\/\/ws3.sinaimg.cn\/large\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/> --><p><!-- <img decoding=\"async\" src=\"https:\/\/raw.githubusercontent.com\/xmt1139057136\/xttblog\/master\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/>--><img decoding=\"async\" src=\"https:\/\/saas.51autoparts.cn\/api\/admin\/sys-file\/oss\/file?fileName=84db51f8561e448f9a4fda2eff0811f9.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/><\/p><p>\u6700\u540e\uff0c\u6b22\u8fce\u5173\u6ce8\u6211\u7684\u4e2a\u4eba\u5fae\u4fe1\u516c\u4f17\u53f7\uff1a\u4e1a\u4f59\u8349\uff08yyucao\uff09\uff01<b>\u53ef\u52a0\u4f5c\u8005\u5fae\u4fe1\u53f7\uff1a<font color=\"red\">xttblog2<\/font>\u3002\u5907\u6ce8\uff1a\u201c1\u201d\uff0c\u6dfb\u52a0\u535a\u4e3b\u5fae\u4fe1\u62c9\u4f60\u8fdb\u5fae\u4fe1\u7fa4\u3002\u5907\u6ce8\u9519\u8bef\u4e0d\u4f1a\u540c\u610f\u597d\u53cb\u7533\u8bf7\u3002<\/b>\u518d\u6b21\u611f\u8c22\u60a8\u7684\u5173\u6ce8\uff01\u540e\u7eed\u6709\u7cbe\u5f69\u5185\u5bb9\u4f1a\u7b2c\u4e00\u65f6\u95f4\u53d1\u7ed9\u60a8\uff01\u539f\u521b\u6587\u7ae0\u6295\u7a3f\u8bf7\u53d1\u9001\u81f3532009913@qq.com\u90ae\u7bb1\u3002\u5546\u52a1\u5408\u4f5c\u4e5f\u53ef\u6dfb\u52a0\u4f5c\u8005\u5fae\u4fe1\u8fdb\u884c\u8054\u7cfb\uff01<\/p><p>\u672c\u6587\u539f\u6587\u51fa\u5904\uff1a<a href=\"https:\/\/www.xttblog.com\">\u4e1a\u4f59\u8349<\/a>\uff1a &raquo; <a href=\"https:\/\/www.xttblog.com\/?p=3375\">\u641e\u4e0d\u61c2 HashMap\uff1f\u53ea\u56e0\u4f60\u7f3a\u4e00\u4e2a HashMap \u7684\u539f\u7406\u673a\u5236\u6d41\u7a0b\u56fe\uff01<\/a><\/p><!-- <div class=\"bd-reward-stl\"><button id=\"bdRewardBtn\"><span><\/span><\/button><\/div> -->","protected":false},"excerpt":{"rendered":"<p>\u5f88\u591a\u4eba\u641e\u4e0d\u61c2 HashMap\uff0c\u6211\u8ba4\u4e3a\u7a76\u5176\u539f\u56e0\u662f\u4ed6\u4eec\u7684\u5b66\u4e60\u65b9\u6cd5\u4e0d\u5bf9\uff01\u4eca\u5929\u6211\u603b\u7ed3\u4e86\u4e00\u4e2a\u5173\u4e8e HashMap \u7684 p [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,6],"tags":[1164,1161,1162,660,1163],"class_list":["post-3375","post","type-post","status-publish","format-standard","hentry","category-java","category-yyzt","tag-concurrenthashmap","tag-hashmap","tag-hashtable","tag-hash","tag-linkedhashmap"],"_links":{"self":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/3375","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3375"}],"version-history":[{"count":1,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/3375\/revisions"}],"predecessor-version":[{"id":3376,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/3375\/revisions\/3376"}],"wp:attachment":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3375"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3375"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3375"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}