
{"id":2173,"date":"2020-08-25T11:42:12","date_gmt":"2020-08-25T03:42:12","guid":{"rendered":"http:\/\/127.0.0.2\/?p=2173"},"modified":"2020-08-25T15:42:39","modified_gmt":"2020-08-25T07:42:39","slug":"2020java%e6%95%99%e7%a8%8b%ef%bc%9amap%e4%bd%93%e7%b3%bb%e9%9b%86%e5%90%88","status":"publish","type":"post","link":"https:\/\/www.9713job.com\/?p=2173","title":{"rendered":"2020java\u6559\u7a0b\uff1aMap\u4f53\u7cfb\u96c6\u5408"},"content":{"rendered":"<h3>Map\u4f53\u7cfb\u96c6\u5408<\/h3>\n<p>Map\u7ed3\u6784<br \/>\ninterface Map<br \/>\n|-Class HashMap<br \/>\n|-interface SortedMap<br \/>\n||-class TreeMap<br \/>\nMap\u7ed3\u6784\u7684\u7279\u70b9\uff1a<br \/>\n1.\u7528\u4e8e\u5b58\u50a8\u4efb\u610f\u952e\u503c\u5bf9(Key&#8211;value)<br \/>\n2.\u952e\uff1a\u65e0\u5e8f\uff0c\u65e0\u4e0b\u6807\uff0c\u4e0d\u5141\u8bb8\u91cd\u590d(\u552f\u4e00)<br \/>\n3.\u503c\uff1a\u65e0\u5e8f\uff0c\u65e0\u4e0b\u6807\uff0c\u5141\u8bb8\u91cd\u590d<!--more--><\/p>\n<p><strong>Map\u7236\u63a5\u53e3<\/strong><\/p>\n<p>\u7279\u70b9\uff1a\u5b58\u50a8\u4e00\u5bf9\u6570\u636e(Key-value)\uff0c\u65e0\u5e8f\uff0c\u65e0\u4e0b\u6807\uff0c\u952e\u4e0d\u53ef\u91cd\u590d\uff0c\u503c\u53ef\u91cd\u590d<br \/>\n\u65b9\u6cd5\uff1a<br \/>\nV put(K key,V value);\/\/\u5c06\u5bf9\u8c61\u5b58\u5165\u5230\u5bf9\u8c61\u4e2d\uff0c\u5173\u8054\u952e\u503c\u3002key\u91cd\u590d\u5219\u8986\u76d6\u539f\u503c<br \/>\nObjet get(Object key);\/\/\u6839\u636e\u952e\u83b7\u53d6\u5bf9\u5e94\u7684\u503c<br \/>\nSet&lt;K&gt; keySet();\/\/\u8fd4\u56de\u6240\u6709Key<br \/>\nCollection&lt;V&gt; values();\/\/\u8fd4\u56de\u5305\u542b\u6240\u6709\u503c\u7684Collection\u96c6\u5408<br \/>\nSet&lt;Map.Entry&lt;K,V&gt;&gt; entrySet();\/\/\u952e\u503c\u5339\u914d\u7684Set\u96c6\u5408<\/p>\n<pre>import java.util.*;\r\n\r\npublic class demos{\r\n    public static void main(String[] args) {\r\n        HashMap&lt;String,String&gt; map=new HashMap&lt;String,String&gt;();\r\n        \/\/\u5b58\r\n        map.put(\"4399\",\"4399\u5c0f\u6e38\u620f\");\r\n        map.put(\"7k7k\",\"7k7k\u6e38\u620f\");\r\n        map.put(\"baidu\",\"\u767e\u5ea6\");\r\n        map.put(\"360\",\"\u5947\u864e\");\r\n        map.put(\"lol\",\"\u82f1\u96c4\u8054\u76df\");\r\n        \/\/\u53d6\u952e\r\n        Set&lt;String&gt; key=map.keySet();\r\n        System.out.println(\"\u83b7\u53d6\u6240\u6709\u952e\");\r\n        for(String str:key){\r\n            System.out.println(str);\r\n        }\r\n        System.out.println(\"===========\");\r\n        \/\/\u53d6\u503c\r\n        Collection&lt;String&gt; value=map.values();\r\n        System.out.println(\"\u83b7\u53d6\u6240\u6709\u7684\u503c\");\r\n        for(String s:value){\r\n            System.out.println(s);\r\n        }\r\n        System.out.println(\"===========\");\r\n        \/\/\u83b7\u53d6\u6240\u6709\u952e\u548c\u503c\r\n        Set&lt;Map.Entry&lt;String,String&gt;&gt; list=map.entrySet();\r\n        System.out.println(\"\u83b7\u53d6\u6240\u6709\u952e\u548c\u503c\");\r\n        for(Map.Entry&lt;String,String&gt; m:list){\r\n            System.out.println(m);\r\n        }\r\n    }\r\n}<\/pre>\n<p><strong>Map\u96c6\u5408\u7684\u5b9e\u73b0\u7c7b<\/strong><\/p>\n<p>HashMap:<br \/>\njdk1.2\u7248\u672c\uff0c\u7ebf\u7a0b\u4e0d\u5b89\u5168\uff0c\u8fd0\u884c\u6548\u7387\u5feb\uff1b\u5141\u8bb8\u7528null\u4f5c\u4e3akey\u6216value<br \/>\nHashtable\uff1a<br \/>\njdk1.0\u7248\u672c\uff0c\u7ebf\u7a0b\u5b89\u5168\uff0c\u8fd0\u884c\u6548\u7387\u6162\uff0c\u4e0d\u5141\u8bb8null\u4f5c\u4e3akey\u6216value<br \/>\nProperies:<br \/>\nHashtable\u7684\u5b50\u7c7b\uff0c\u8981\u6c42key\u548cvalue\u90fd\u662fString\u3002\u901a\u5e38\u7528\u4e8e\u914d\u7f6e\u6587\u4ef6\u7684\u8bfb\u53d6<br \/>\nTreeMap\uff1a<br \/>\n\u5b9e\u73b0\u4e86SortedMap\u63a5\u53e3(\u662fMap\u5b50\u63a5\u53e3)\uff0c\u53ef\u4ee5\u5bf9key\u81ea\u52a8\u6392\u5e8f<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Map\u4f53\u7cfb\u96c6\u5408 Map\u7ed3\u6784 interface Map |-Class HashMap |-interface [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-2173","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/www.9713job.com\/index.php?rest_route=\/wp\/v2\/posts\/2173","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.9713job.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.9713job.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.9713job.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.9713job.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2173"}],"version-history":[{"count":5,"href":"https:\/\/www.9713job.com\/index.php?rest_route=\/wp\/v2\/posts\/2173\/revisions"}],"predecessor-version":[{"id":2178,"href":"https:\/\/www.9713job.com\/index.php?rest_route=\/wp\/v2\/posts\/2173\/revisions\/2178"}],"wp:attachment":[{"href":"https:\/\/www.9713job.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2173"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.9713job.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2173"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.9713job.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2173"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}