Map\u4f5c\u4e3ajava\u4e2d\u5341\u5206\u5e38\u7528\u7684\u96c6\u5408\uff0c\u6211\u4eec\u5bf9\u96c6\u5408\u5143\u7d20\u7684\u904d\u5386\u65b9\u5f0f\u8981\u5341\u5206\u719f\u6089\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n\u9996\u5148\u6784\u9020\u4e00\u4e2a HashMap \u96c6\u5408\uff1a<\/p>\n
\r\nHashMap map = new HashMap<>();\r\nmap.put(\"A\",\"1\");\r\nmap.put(\"B\",\"2\");\r\nmap.put(\"C\",\"3\");\r\n<\/pre>\n1. \u5206\u522b\u83b7\u53d6 key \u96c6\u5408\u548c value \u96c6\u5408<\/strong><\/div>\n\r\n \/\/1\u3001\u5206\u522b\u83b7\u53d6key\u548cvalue\u7684\u96c6\u5408\r\n for(String key : map.keySet()){\r\n System.out.println(key);\r\n }\r\n for(Object value : map.values()){\r\n System.out.println(value);\r\n }\r\n<\/pre>\n2. \u83b7\u53d6 key \u96c6\u5408\uff0c\u7136\u540e\u904d\u5386key\u96c6\u5408\uff0c\u6839\u636ekey\u5206\u522b\u5f97\u5230\u76f8\u5e94value<\/strong><\/div>\n\r\n \/\/2\u3001\u83b7\u53d6key\u96c6\u5408\uff0c\u7136\u540e\u904d\u5386key\uff0c\u6839\u636ekey\u5f97\u5230 value\r\n Set keySet = map.keySet();\r\n for(String str : keySet){\r\n System.out.println(str+\"-\"+map.get(str));\r\n }\r\n<\/string><\/pre>\n3. \u5f97\u5230 Entry \u96c6\u5408\uff0c\u7136\u540e\u904d\u5386 Entry<\/strong><\/div>\n\r\n \/\/3\u3001\u5f97\u5230 Entry \u96c6\u5408\uff0c\u7136\u540e\u904d\u5386 Entry\r\n Set> entrySet = map.entrySet();\r\n for(Map.Entry entry : entrySet){\r\n System.out.println(entry.getKey()+\"-\"+entry.getValue());\r\n }\r\n<\/pre>\n4. \u8fed\u4ee3<\/strong><\/div>\n\r\n \/\/4\u3001\u8fed\u4ee3\r\n Iterator> iterator = map.entrySet().iterator();\r\n while(iterator.hasNext()){\r\n Map.Entry mapEntry = iterator.next();\r\n System.out.println(mapEntry.getKey()+\"-\"+mapEntry.getValue());\r\n }\r\n<\/pre>\n\u603b\u7ed3<\/strong><\/div>\n\u57fa\u672c\u4e0a\u4f7f\u7528\u7b2c\u4e09\u79cd\u65b9\u6cd5\u662f\u6027\u80fd\u6700\u597d\u7684\uff0c\u7b2c\u4e00\u79cd\u904d\u5386\u65b9\u6cd5\u5728\u6211\u4eec\u53ea\u9700\u8981 key \u96c6\u5408\u6216\u8005\u53ea\u9700\u8981 value \u96c6\u5408\u65f6\u4f7f\u7528\uff1b\u7b2c\u4e8c\u79cd\u65b9\u6cd5\u6548\u7387\u5f88\u4f4e\uff0c\u4e0d\u63a8\u8350\u4f7f\u7528\uff1b\u7b2c\u56db\u79cd\u65b9\u6cd5\u6548\u7387\u4e5f\u633a\u597d\uff0c\u5173\u952e\u662f\u5728\u904d\u5386\u7684\u8fc7\u7a0b\u4e2d\u6211\u4eec\u53ef\u4ee5\u5bf9\u96c6\u5408\u4e2d\u7684\u5143\u7d20\u8fdb\u884c\u5220\u9664\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"
\u9996\u5148\u6784\u9020\u4e00\u4e2a HashMap \u96c6\u5408\uff1a HashMap map = new HashMap(); map.put […]<\/p>\n","protected":false},"author":1903,"featured_media":210321,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-210232","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/210232","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1903"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=210232"}],"version-history":[{"count":5,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/210232\/revisions"}],"predecessor-version":[{"id":210381,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/210232\/revisions\/210381"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/210321"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=210232"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=210232"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=210232"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}