{"id":1736,"date":"2016-10-09T15:56:01","date_gmt":"2016-10-09T07:56:01","guid":{"rendered":"https:\/\/ai.zhousir.top\/?p=1736"},"modified":"2026-08-18T12:09:36","modified_gmt":"2026-08-18T04:09:36","slug":"hashmap%e7%9a%84%e5%b7%a5%e4%bd%9c%e5%8e%9f%e7%90%86","status":"publish","type":"post","link":"https:\/\/ai.zhousir.top\/?p=1736","title":{"rendered":"HashMap\u7684\u5de5\u4f5c\u539f\u7406"},"content":{"rendered":"<section id=\"wenyan\" style=\"font-family: system-ui, 'Apple Color Emoji', 'Segoe UI', 'Segoe UI Symbol', 'Noto Sans', Roboto, sans-serif; line-height: 1.75; font-size: 16px; color: #000000; caret-color: #000000;\" data-provider=\"WenYan\">\n<p style=\"margin: 1em 0px;\">\u9762\u8bd5\u5e38\u4ece\u201c\u4f60\u7528\u8fc7 HashMap \u5417\uff1f\u4ec0\u4e48\u662f HashMap\uff1f\u4e3a\u4ec0\u4e48\u7528\u5b83\uff1f\u201d\u95ee\u8d77\u3002\u591a\u6570\u4eba\u4f1a\u7b54\uff1a\u662f\u7684\uff0c\u7136\u540e\u5217\u51fa\u7279\u6027\u2014\u2014<strong style=\"color: #4870ac;\">HashMap \u53ef\u4ee5\u63a5\u53d7 null \u952e\u548c\u503c\uff0cHashtable \u4e0d\u884c<\/strong>\uff1b<strong style=\"color: #4870ac;\">HashMap \u975e synchronized<\/strong>\uff1b<strong style=\"color: #4870ac;\">HashMap \u5f88\u5feb<\/strong>\uff1b<strong style=\"color: #4870ac;\">\u5b58\u7684\u662f\u952e\u503c\u5bf9<\/strong>\u3002\u8fd9\u53ea\u80fd\u8bf4\u660e\u4f60\u7528\u8fc7\u5b83\u3002\u63a5\u4e0b\u6765\u9762\u8bd5\u5b98\u4f1a\u5f80\u539f\u7406\u4e0a\u8ffd\u3002<\/p>\n<p style=\"margin: 1em 0px;\">\u201c\u4f60\u77e5\u9053 HashMap \u7684\u5de5\u4f5c\u539f\u7406\u5417\uff1fget() \u600e\u4e48\u5de5\u4f5c\uff1f\u201d\u6709\u4eba\u4f1a\u8bf4\u53bb\u770b\u6e90\u7801\u6216 Google\u3002\u80fd\u7b54\u5230\u70b9\u5b50\u4e0a\u7684\u4eba\u4f1a\u8bf4\uff1a<strong style=\"color: #4870ac;\">HashMap \u57fa\u4e8e hashing<\/strong>\uff0c\u7528 <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">put(key, value)<\/code> \u5b58\u3001<code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">get(key)<\/code> \u53d6\u3002\u8c03\u7528 put \u65f6\u5148\u5bf9\u952e\u505a <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">hashCode()<\/code>\uff0c\u7528\u8fd4\u56de\u503c\u5b9a\u4f4d bucket\uff0c\u518d\u628a <strong style=\"color: #4870ac;\">Entry\uff08\u952e\u5bf9\u8c61+\u503c\u5bf9\u8c61\uff09<\/strong> \u653e\u8fdb\u53bb\u3002\u5173\u952e\u70b9\u662f bucket \u91cc\u5b58\u7684\u662f <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">Map.Entry<\/code>\uff0c\u4e0d\u662f\u53ea\u5b58 value\u2014\u2014\u5426\u5219\u540e\u9762\u201c\u600e\u4e48\u53d6\u51fa\u5bf9\u8c61\u201d\u6839\u672c\u8bb2\u4e0d\u6e05\u3002<\/p>\n<h2 style=\"padding: 1px 12.5px; color: #ffffff; margin: 1.2em 0px 1em; border-radius: 4px; display: inline-block; background-color: #4870ac; font-size: 1.3em;\">\u4e00\u3001hashCode \u76f8\u540c\uff1a\u78b0\u649e<\/h2>\n<p style=\"margin: 1em 0px;\">\u201c\u4e24\u4e2a\u5bf9\u8c61 hashcode \u76f8\u540c\u4f1a\u53d1\u751f\u4ec0\u4e48\uff1f\u201d\u6709\u4eba\u4f1a\u8bef\u4ee5\u4e3a\u5bf9\u8c61\u76f8\u7b49\u3001HashMap \u629b\u5f02\u5e38\u6216\u4e0d\u5b58\u3002\u9762\u8bd5\u5b98\u4f1a\u63d0\u9192\uff1a<code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">equals()<\/code> \u548c <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">hashCode()<\/code> \u662f\u4e24\u56de\u4e8b\uff0chashcode \u76f8\u540c\u4e5f\u53ef\u4ee5\u4e0d\u76f8\u7b49\u3002\u7ee7\u7eed\u7b54\uff1a<strong style=\"color: #4870ac;\">bucket \u4f4d\u7f6e\u76f8\u540c\uff0c\u53d1\u751f\u78b0\u649e<\/strong>\u3002HashMap \u7528\u94fe\u8868\u5b58\u5bf9\u8c61\uff0c\u8fd9\u4e2a Entry \u4f1a\u6302\u5230\u94fe\u8868\u4e0a\u3002\u5904\u7406\u78b0\u649e\u7684\u65b9\u6cd5\u5f88\u591a\uff0c\u94fe\u8868\u662f\u6700\u7b80\u5355\u7684\u4e00\u79cd\uff0c\u4e5f\u6b63\u662f\uff08Java 7 \u53ca\u66f4\u65e9\uff09HashMap \u7684\u505a\u6cd5\u3002<\/p>\n<p style=\"margin: 1em 0px;\">\u201c\u4e24\u4e2a\u952e hashcode \u76f8\u540c\uff0c\u5982\u4f55\u83b7\u53d6\u503c\u5bf9\u8c61\uff1f\u201d\u5148\u7528\u952e\u7684 hashcode \u627e\u5230 bucket\uff0c\u518d<strong style=\"color: #4870ac;\">\u904d\u5386\u94fe\u8868<\/strong>\u3002\u9762\u8bd5\u5b98\u4f1a\u8ffd\u95ee\uff1a\u4f60\u6ca1\u6709\u503c\u5bf9\u8c61\u53ef\u6bd4\u8f83\uff0c\u600e\u4e48\u786e\u5b9a\u627e\u5230\u4e86\uff1f\u9664\u975e\u4f60\u77e5\u9053\u94fe\u8868\u8282\u70b9\u91cc\u662f\u952e\u503c\u5bf9\uff0c\u5426\u5219\u7b54\u4e0d\u4e0a\u3002\u8bb0\u4f4f\u8fd9\u4e00\u70b9\u7684\u4eba\u4f1a\u8bf4\uff1a\u627e\u5230 bucket \u540e\u8c03\u7528 <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">keys.equals()<\/code> \u627e\u5230\u6b63\u786e\u8282\u70b9\uff0c\u518d\u53d6 value\u3002\u5b8c\u7f8e\u7b54\u6848\u3002<\/p>\n<p style=\"margin: 1em 0px;\">\u5f88\u591a\u4eba\u5728\u8fd9\u4e00\u73af\u628a <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">hashCode()<\/code> \u548c <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">equals()<\/code> \u641e\u6df7\uff1ahashCode \u4e00\u8def\u51fa\u573a\uff0cequals \u53ea\u5728\u53d6 value \u65f6\u51fa\u73b0\u3002\u4f18\u79c0\u5f00\u53d1\u8005\u8fd8\u4f1a\u8865\u5145\uff1a\u952e\u7528\u4e0d\u53ef\u53d8\u3001final \u5bf9\u8c61\uff0c\u5e76\u6b63\u786e\u5b9e\u73b0 equals\/hashCode\uff0c\u80fd\u51cf\u5c11\u78b0\u649e\u3001\u63d0\u9ad8\u6548\u7387\u3002\u4e0d\u53ef\u53d8\u6027\u8ba9 hashcode \u53ef\u7f13\u5b58\uff0c<code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">String<\/code>\u3001<code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">Integer<\/code> \u8fd9\u7c7b\u5305\u88c5\u7c7b\u5f53\u952e\u5f88\u5408\u9002\u3002<\/p>\n<h2 style=\"padding: 1px 12.5px; color: #ffffff; margin: 1.2em 0px 1em; border-radius: 4px; display: inline-block; background-color: #4870ac; font-size: 1.3em;\">\u4e8c\u3001\u8d1f\u8f7d\u56e0\u5b50\u4e0e\u6269\u5bb9<\/h2>\n<p style=\"margin: 1em 0px;\">\u201cHashMap \u5927\u5c0f\u8d85\u8fc7\u8d1f\u8f7d\u56e0\u5b50\uff08load factor\uff09\u5b9a\u4e49\u7684\u5bb9\u91cf\u600e\u4e48\u529e\uff1f\u201d\u9ed8\u8ba4\u8d1f\u8f7d\u56e0\u5b50\u662f <strong style=\"color: #4870ac;\">0.75<\/strong>\uff1abucket \u586b\u5230 75% \u65f6\uff0c\u4f1a\u521b\u5efa\u539f\u6765\u4e24\u500d\u5927\u5c0f\u7684 bucket \u6570\u7ec4\uff0c\u628a\u65e7\u5bf9\u8c61\u653e\u8fdb\u53bb\u3002\u8fd9\u4e2a\u8fc7\u7a0b\u53eb <strong style=\"color: #4870ac;\">rehashing<\/strong>\uff0c\u56e0\u4e3a\u8981\u518d\u8c03 hash \u627e\u65b0\u4f4d\u7f6e\u3002<\/p>\n<p style=\"margin: 1em 0px;\">\u201c\u91cd\u65b0\u8c03\u6574\u5927\u5c0f\u6709\u4ec0\u4e48\u95ee\u9898\uff1f\u201d\u591a\u7ebf\u7a0b\u4e0b\u53ef\u80fd\u4ea7\u751f\u6761\u4ef6\u7ade\u4e89\uff08race condition\uff09\u3002\u4e24\u4e2a\u7ebf\u7a0b\u540c\u65f6\u53d1\u73b0\u9700\u8981\u6269\u5bb9\uff0c\u4f1a\u4e00\u8d77\u8c03\u6574\u3002\u79fb\u52a8\u5230\u65b0 bucket \u65f6\uff0cHashMap \u628a\u5143\u7d20\u653e\u5728\u94fe\u8868<strong style=\"color: #4870ac;\">\u5934\u90e8<\/strong>\u800c\u4e0d\u662f\u5c3e\u90e8\uff08\u907f\u514d\u5c3e\u90e8\u904d\u5386\uff09\uff0c\u94fe\u8868\u6b21\u5e8f\u4f1a\u53cd\u8fc7\u6765\u3002\u6761\u4ef6\u7ade\u4e89\u4e00\u65e6\u53d1\u751f\uff0c\u53ef\u80fd\u6b7b\u5faa\u73af\u3002\u8fd9\u65f6\u53ef\u4ee5\u53cd\u95ee\uff1a\u4e3a\u4ec0\u4e48\u8981\u5728\u591a\u7ebf\u7a0b\u91cc\u7528 HashMap\uff1f<\/p>\n<table style=\"display: table; text-align: left; overflow: auto; border-collapse: collapse; margin: 1.4em auto; max-width: 100%; table-layout: fixed; overflow-wrap: break-word; word-break: break-all;\" width=\"800\">\n<thead>\n<tr>\n<th style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top; text-align: center; font-weight: bold; color: #4870ac; background: #f7f7f7;\">\u95ee\u9898<\/th>\n<th style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top; text-align: center; font-weight: bold; color: #4870ac; background: #f7f7f7;\">\u8981\u70b9<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">put \/ get<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">hashCode \u5b9a\u4f4d bucket\uff0cEntry \u5b58\u952e\u503c\u5bf9<\/td>\n<\/tr>\n<tr>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u78b0\u649e<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u540c\u4e00 bucket \u7528\u94fe\u8868\uff08Java 8 \u8d77\u957f\u94fe\u4f1a\u8f6c\u7ea2\u9ed1\u6811\uff09<\/td>\n<\/tr>\n<tr>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u53d6 value<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">bucket \u5185\u7528 key.equals() \u627e\u5230\u8282\u70b9<\/td>\n<\/tr>\n<tr>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u8d1f\u8f7d\u56e0\u5b50<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u9ed8\u8ba4 0.75\uff0c\u8d85\u4e86\u6269\u5bb9\u4e3a\u7ea6 2 \u500d\u5e76 rehash<\/td>\n<\/tr>\n<tr>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u591a\u7ebf\u7a0b\u6269\u5bb9<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u94fe\u8868\u5934\u63d2\u53ef\u80fd\u5bfc\u81f4\u6b7b\u5faa\u73af\uff0c\u6539\u7528 ConcurrentHashMap<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2 style=\"padding: 1px 12.5px; color: #ffffff; margin: 1.2em 0px 1em; border-radius: 4px; display: inline-block; background-color: #4870ac; font-size: 1.3em;\">\u4e09\u3001\u952e\u7684\u9009\u62e9\u4e0e ConcurrentHashMap<\/h2>\n<p style=\"margin: 1em 0px;\"><strong style=\"color: #4870ac;\">\u4e3a\u4ec0\u4e48 String\u3001Integer \u9002\u5408\u5f53\u952e\uff1f<\/strong> \u5b83\u4eec\u4e0d\u53ef\u53d8\u3001final\uff0c\u5df2\u91cd\u5199 equals \u548c hashCode\u3002\u4e0d\u53ef\u53d8\u6027\u5fc5\u8981\uff1a\u8ba1\u7b97 hashCode \u65f6\u952e\u4e0d\u80fd\u53d8\uff0c\u5426\u5219\u653e\u5165\u548c\u53d6\u51fa\u65f6 hash \u4e0d\u540c\uff0c\u5c31\u627e\u4e0d\u5230\u5bf9\u8c61\u3002\u4e0d\u53ef\u53d8\u8fd8\u6709\u7ebf\u7a0b\u5b89\u5168\u7b49\u597d\u5904\u3002\u4e24\u4e2a\u4e0d\u76f8\u7b49\u7684\u5bf9\u8c61\u82e5\u8fd4\u56de\u4e0d\u540c hashcode\uff0c\u78b0\u649e\u66f4\u5c11\uff0c\u6027\u80fd\u66f4\u597d\u3002<\/p>\n<p style=\"margin: 1em 0px;\"><strong style=\"color: #4870ac;\">\u53ef\u4ee5\u7528\u81ea\u5b9a\u4e49\u5bf9\u8c61\u5f53\u952e\u5417\uff1f<\/strong> \u53ef\u4ee5\uff0c\u53ea\u8981\u9075\u5b88 equals\/hashCode \u7ea6\u5b9a\uff0c\u5e76\u4e14\u63d2\u5165 Map \u540e\u4e0d\u518d\u6539\u53d8\u3002\u81ea\u5b9a\u4e49\u5bf9\u8c61\u82e5\u4e0d\u53ef\u53d8\uff0c\u521b\u5efa\u540e\u5c31\u4e0d\u80fd\u6539\uff0c\u5df2\u7ecf\u6ee1\u8db3\u5f53\u952e\u7684\u6761\u4ef6\u3002<\/p>\n<p style=\"margin: 1em 0px;\"><strong style=\"color: #4870ac;\">\u80fd\u7528 ConcurrentHashMap \u4ee3\u66ff Hashtable \u5417\uff1f<\/strong> Hashtable \u6574\u8868 synchronized\uff1bConcurrentHashMap \u53ea\u9501\u4e00\u90e8\u5206\uff08\u5206\u6bb5\u6216\u6876\uff09\uff0c\u540c\u6b65\u6027\u80fd\u66f4\u597d\u3002\u53ef\u4ee5\u4ee3\u66ff Hashtable\uff0c\u4f46 Hashtable \u63d0\u4f9b\u66f4\u5f3a\u7684\u6574\u8868\u4e92\u65a5\u3002\u8be6\u89c1 <a href=\"http:\/\/javarevisited.blogspot.sg\/2011\/04\/difference-between-concurrenthashmap.html\">\u8fd9\u7bc7\u535a\u5ba2<\/a>\u3002<\/p>\n<h2 style=\"padding: 1px 12.5px; color: #ffffff; margin: 1.2em 0px 1em; border-radius: 4px; display: inline-block; background-color: #4870ac; font-size: 1.3em;\">\u56db\u3001\u8fd9\u4e9b\u95ee\u9898\u8986\u76d6\u54ea\u4e9b\u77e5\u8bc6\u70b9<\/h2>\n<ul style=\"padding-left: 1rem; margin-left: 1rem; font-size: 0.9rem; list-style-type: disc;\">\n<li>\n<section>hashing \u7684\u6982\u5ff5<\/section>\n<\/li>\n<li>\n<section>HashMap \u4e2d\u89e3\u51b3\u78b0\u649e\u7684\u65b9\u6cd5<\/section>\n<\/li>\n<li>\n<section>equals() \u548c hashCode() \u7684\u5e94\u7528\uff0c\u4ee5\u53ca\u5b83\u4eec\u5728 HashMap \u4e2d\u7684\u91cd\u8981\u6027<\/section>\n<\/li>\n<li>\n<section>\u4e0d\u53ef\u53d8\u5bf9\u8c61\u7684\u597d\u5904<\/section>\n<\/li>\n<li>\n<section>HashMap \u591a\u7ebf\u7a0b\u7684\u6761\u4ef6\u7ade\u4e89<\/section>\n<\/li>\n<li>\n<section>\u91cd\u65b0\u8c03\u6574 HashMap \u7684\u5927\u5c0f<\/section>\n<\/li>\n<\/ul>\n<p style=\"margin: 1em 0px;\">\u6ce8\uff1a\u54c8\u5e0c\u8868\u2014\u2014\u5728\u5bf9\u8c61\u5b58\u50a8\u4f4d\u7f6e\u548c\u5173\u952e\u5c5e\u6027 k \u4e4b\u95f4\u5efa\u7acb\u5bf9\u5e94\u5173\u7cfb f\uff0c\u4f7f\u6bcf\u4e2a\u5bf9\u8c61\u5bf9\u5e94\u552f\u4e00\u4f4d\u7f6e\u3002\u67e5\u627e\u65f6\u8ba1\u7b97 f(k)\uff1b\u82e5\u5bf9\u8c61\u5728\u96c6\u5408\u4e2d\uff0c\u5fc5\u5728 f(k) \u4e0a\u3002\u79f0 f \u4e3a\u54c8\u5e0c\u65b9\u6cd5\uff0c\u6309\u6b64\u5efa\u7acb\u7684\u8868\u4e3a\u54c8\u5e0c\u8868\u3002<\/p>\n<h2 style=\"padding: 1px 12.5px; color: #ffffff; margin: 1.2em 0px 1em; border-radius: 4px; display: inline-block; background-color: #4870ac; font-size: 1.3em;\">\u4e94\u3001\u5de5\u4f5c\u539f\u7406\u5c0f\u7ed3<\/h2>\n<p style=\"margin: 1em 0px;\">HashMap \u53ca\u5176\u5b50\u7c7b\u7528 Hash \u7b97\u6cd5\u51b3\u5b9a\u5143\u7d20\u4f4d\u7f6e\u3002\u521d\u59cb\u5316\u65f6\u521b\u5efa\u957f\u5ea6\u4e3a capacity \u7684 Entry \u6570\u7ec4\uff0c\u53ef\u5b58\u5143\u7d20\u7684\u4f4d\u7f6e\u53eb\u201c\u6876\uff08bucket\uff09\u201d\uff0c\u6309\u7d22\u5f15\u53ef\u5feb\u901f\u8bbf\u95ee\u3002\u6bcf\u4e2a\u6876\u901a\u5e38\u5148\u5b58\u4e00\u4e2a Entry\uff1bEntry \u53ef\u6307\u5411\u4e0b\u4e00\u4e2a Entry\uff0c\u4e8e\u662f\u5f62\u6210 Entry \u94fe\uff1a\u6876\u91cc\u53ea\u6709\u4e00\u4e2a\u5934\u7ed3\u70b9\uff0c\u4f46\u5b83\u4e32\u7740\u4e00\u6761\u94fe\u3002<\/p>\n<p style=\"margin: 1em 0px;\">put \u65f6\u5bf9\u952e\u7b97 hashcode \u627e bucket\uff1bget \u65f6\u5148\u627e bucket\uff0c\u518d\u7528 equals \u627e\u6b63\u786e\u952e\u503c\u5bf9\u3002\u78b0\u649e\u65f6\u5bf9\u8c61\u653e\u5728\u94fe\u8868\u4e0b\u4e00\u8282\u70b9\u3002\u6bcf\u4e2a\u94fe\u8868\u8282\u70b9\u5b58\u7684\u662f\u952e\u503c\u5bf9\u5bf9\u8c61\u3002\u4e24\u4e2a\u4e0d\u540c\u952e hashcode \u76f8\u540c\u65f6\uff0c\u5b83\u4eec\u5728\u540c\u4e00 bucket \u7684\u94fe\u8868\u91cc\uff0c\u9760 equals \u533a\u5206\u3002<\/p>\n<p style=\"margin: 1em 0px;\">\u56e0\u4e3a HashMap \u597d\u5904\u5f88\u591a\uff0c\u66fe\u5728\u7535\u5546\u5e94\u7528\u91cc\u62ff\u5b83\u5f53\u7f13\u5b58\u3002\u91d1\u878d\u9886\u57df\u4e5f\u5f88\u5e38\u7528 HashMap \u548c ConcurrentHashMap\u3002<\/p>\n<p style=\"margin: 1em 0px;\"><a href=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2016\/10\/hashmap.jpg\" rel=\"fancybox\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-1739\" src=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2016\/10\/hashmap.jpg\" alt=\"hashmap\" width=\"590\" height=\"627\" \/><\/a><\/p>\n<p style=\"margin: 1em 0px;\">\u539f\u6587\uff1a<a class=\"external\" href=\"http:\/\/javarevisited.blogspot.hk\/2011\/02\/how-hashmap-works-in-java.html\" target=\"_blank\" rel=\"nofollow\">Javarevisited<\/a>\u3000\u7ffb\u8bd1\uff1a<a href=\"http:\/\/www.importnew.com\/\">ImportNew.com<\/a> &#8211; <a href=\"http:\/\/www.importnew.com\/author\/tangxiaojuan\">\u5510\u5c0f\u5a1f<\/a>\u3000\u8bd1\u6587\uff1a<a href=\"http:\/\/www.importnew.com\/7099.html\">http:\/\/www.importnew.com\/7099.html<\/a><\/p>\n<blockquote style=\"display: block; font-size: 0.9em; border-left: 3px solid #4870ac; padding: 0.5em 1em; margin: 0px; background: #f6f8fa; color: #40464f;\">\n<p style=\"margin: 1em 0px;\"><strong style=\"color: #4870ac;\">\u4e00\u53e5\u8bdd\u603b\u7ed3\uff1aHashMap \u7528 hashCode \u5b9a\u4f4d\u6876\u3001\u7528 equals \u5728\u94fe\u4e0a\u627e\u952e\uff1b\u78b0\u649e\u7528\u94fe\u8868\uff0c\u88c5\u6ee1\u7ea6 75% \u5c31\u6269\u5bb9 rehash\u2014\u2014\u5355\u7ebf\u7a0b\u5f88\u5feb\uff0c\u591a\u7ebf\u7a0b\u6269\u5bb9\u53ef\u80fd\u6b7b\u5faa\u73af\u3002<\/strong><\/p>\n<\/blockquote>\n<\/section>\n","protected":false},"excerpt":{"rendered":"<p>\u9762\u8bd5\u5e38\u4ece\u201c\u4f60\u7528\u8fc7 HashMap \u5417\uff1f\u4ec0\u4e48\u662f HashMap\uff1f\u4e3a\u4ec0\u4e48\u7528\u5b83\uff1f\u201d\u95ee\u8d77\u3002\u591a\u6570\u4eba\u4f1a\u7b54\uff1a\u662f\u7684\uff0c\u7136\u540e\u5217\u51fa\u7279 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[18],"tags":[177],"_links":{"self":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/1736"}],"collection":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1736"}],"version-history":[{"count":3,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/1736\/revisions"}],"predecessor-version":[{"id":2067,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/1736\/revisions\/2067"}],"wp:attachment":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1736"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1736"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1736"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}