{"id":84,"date":"2021-04-26T12:37:31","date_gmt":"2021-04-26T04:37:31","guid":{"rendered":"http:\/\/112.124.66.68\/?p=84"},"modified":"2021-04-26T12:37:31","modified_gmt":"2021-04-26T04:37:31","slug":"hashmap%e5%92%8chashtable%e7%9a%84%e5%8c%ba%e5%88%ab","status":"publish","type":"post","link":"https:\/\/sanlangcode.com\/index.php\/2021\/04\/26\/hashmap%e5%92%8chashtable%e7%9a%84%e5%8c%ba%e5%88%ab\/","title":{"rendered":"HashMap\u548cHashTable\u7684\u533a\u522b"},"content":{"rendered":"<p>1\u3001\u4e24\u8005\u7236\u7c7b\u4e0d\u540c<br \/>\nHashMap\u662f\u7ee7\u627f\u81eaAbstractMap\u7c7b\uff0c\u800cHashtable\u662f\u7ee7\u627f\u81eaDictionary\u7c7b\u3002\u4e0d\u8fc7\u5b83\u4eec\u90fd\u5b9e\u73b0\u4e86\u540c\u65f6\u5b9e\u73b0<br \/>\n\u4e86map\u3001Cloneable\uff08\u53ef\u590d\u5236\uff09\u3001Serializable\uff08\u53ef\u5e8f\u5217\u5316\uff09\u8fd9\u4e09\u4e2a\u63a5\u53e3\u3002<\/p>\n<p>2\u3001\u5bf9\u5916\u63d0\u4f9b\u7684\u63a5\u53e3\u4e0d\u540c<br \/>\nHashtable\u6bd4HashMap\u591a\u63d0\u4f9b\u4e86elments() \u548ccontains() \u4e24\u4e2a\u65b9\u6cd5\u3002<br \/>\nelments() \u65b9\u6cd5\u7ee7\u627f\u81eaHashtable\u7684\u7236\u7c7bDictionnary\u3002<br \/>\nelements() \u65b9\u6cd5\u7528\u4e8e\u8fd4\u56de\u6b64Hashtable\u4e2d\u7684value\u7684\u679a\u4e3e\u3002<br \/>\ncontains()\u65b9\u6cd5\u5224\u65ad\u8be5Hashtable\u662f\u5426\u5305\u542b\u4f20\u5165\u7684value\u3002\u5b83\u7684\u4f5c\u7528\u4e0econtainsValue()\u4e00\u81f4\u3002\u4e8b\u5b9e\u4e0a\uff0ccontansValue() \u5c31\u53ea\u662f\u8c03\u7528\u4e86\u4e00\u4e0bcontains() \u65b9\u6cd5\u3002<!--more--><\/p>\n<p>3\u3001\u5bf9null\u7684\u652f\u6301\u4e0d\u540c<br \/>\nHashtable\uff1akey\u548cvalue\u90fd\u4e0d\u80fd\u4e3anull\u3002<br \/>\nint[] a = new int[4];\/\/\u63a8\u4ecb\u4f7f\u7528int[] \u8fd9\u79cd\u65b9\u5f0f\u521d\u59cb\u5316<br \/>\nint c[] = {23,43,56,78};\/\/\u957f\u5ea6\uff1a4\uff0c\u7d22\u5f15\u8303\u56f4\uff1a[0,3]<br \/>\nHashMap\uff1akey\u53ef\u4ee5\u4e3anull\uff0c\u4f46\u662f\u8fd9\u6837\u7684key\u53ea\u80fd\u6709\u4e00\u4e2a\uff0c<br \/>\n\u56e0\u4e3a\u5fc5\u987b\u4fdd\u8bc1key\u7684\u552f\u4e00\u6027\uff1b\u53ef\u4ee5\u6709\u591a\u4e2akey\u503c\u5bf9\u5e94\u7684value\u4e3anull\u3002<\/p>\n<p>4\u3001\u5b89\u5168\u6027\u4e0d\u540c<br \/>\nHashMap\u662f\u7ebf\u7a0b\u4e0d\u5b89\u5168\u7684\uff0c\u5728\u591a\u7ebf\u7a0b\u5e76\u53d1\u7684\u73af\u5883\u4e0b\uff0c<br \/>\n\u53ef\u80fd\u4f1a\u4ea7\u751f\u6b7b\u9501\u7b49\u95ee\u9898\uff0c\u56e0\u6b64\u9700\u8981\u5f00\u53d1\u4eba\u5458\u81ea\u5df1\u5904\u7406\u591a\u7ebf\u7a0b\u7684\u5b89\u5168\u95ee\u9898\u3002<br \/>\nHashtable\u662f\u7ebf\u7a0b\u5b89\u5168\u7684\uff0c\u5b83\u7684\u6bcf\u4e2a\u65b9\u6cd5\u4e0a\u90fd\u6709synchronized \u5173\u952e\u5b57\uff0c\u56e0\u6b64\u53ef\u76f4\u63a5\u7528\u4e8e\u591a\u7ebf\u7a0b\u4e2d\u3002<br \/>\n\u867d\u7136HashMap\u662f\u7ebf\u7a0b\u4e0d\u5b89\u5168\u7684\uff0c\u4f46\u662f\u5b83\u7684\u6548\u7387\u8fdc\u8fdc\u9ad8\u4e8eHashtable\uff0c<br \/>\n\u8fd9\u6837\u8bbe\u8ba1\u662f\u5408\u7406\u7684\uff0c\u56e0\u4e3a\u5927\u90e8\u5206\u7684\u4f7f\u7528\u573a\u666f\u90fd\u662f\u5355\u7ebf\u7a0b\u3002<br \/>\n\u5f53\u9700\u8981\u591a\u7ebf\u7a0b\u64cd\u4f5c\u7684\u65f6\u5019\u53ef\u4ee5\u4f7f\u7528\u7ebf\u7a0b\u5b89\u5168\u7684ConcurrentHashMap\u3002<br \/>\nConcurrentHashMap\u867d\u7136\u4e5f\u662f\u7ebf\u7a0b\u5b89\u5168\u7684\uff0c\u4f46\u662f\u5b83\u7684\u6548\u7387\u6bd4Hashtable\u8981\u9ad8\u597d\u591a\u500d<br \/>\n\u56e0\u4e3aConcurrentHashMap\u4f7f\u7528\u4e86\u5206\u6bb5\u9501\uff0c\u5e76\u4e0d\u5bf9\u6574\u4e2a\u6570\u636e\u8fdb\u884c\u9501\u5b9a\u3002<\/p>\n<p>5\u3001\u521d\u59cb\u5bb9\u91cf\u5927\u5c0f\u548c\u6bcf\u6b21\u6269\u5145\u5bb9\u91cf\u5927\u5c0f\u4e0d\u540c<br \/>\n6\u3001\u8ba1\u7b97hash\u503c\u7684\u65b9\u6cd5\u4e0d\u540c<\/p>\n","protected":false},"excerpt":{"rendered":"<p>1\u3001\u4e24\u8005\u7236\u7c7b\u4e0d\u540c HashMap&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":325,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-84","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-java"],"_links":{"self":[{"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/posts\/84","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/comments?post=84"}],"version-history":[{"count":0,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/posts\/84\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/media\/325"}],"wp:attachment":[{"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/media?parent=84"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/categories?post=84"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/tags?post=84"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}