{"id":1003,"date":"2014-05-28T09:47:01","date_gmt":"2014-05-28T09:47:01","guid":{"rendered":"http:\/\/blog.zhukunqian.com\/?p=1003"},"modified":"2014-05-28T09:47:01","modified_gmt":"2014-05-28T09:47:01","slug":"%e4%bb%8a%e5%a4%a9%e6%83%b3%e6%b5%8b%e8%af%95map%e7%9a%84%e8%af%bb%e5%8f%96key%e7%9a%84%e6%80%a7%e8%83%bd%ef%bc%8c%e7%bb%93%e6%9e%9c%e9%81%87%e5%88%b0%e6%97%a0%e6%b3%95%e8%a7%a3%e7%ad%94%e7%9a%84","status":"publish","type":"post","link":"https:\/\/blog.zhukunqian.com\/?p=1003","title":{"rendered":"\u4eca\u5929\u60f3\u6d4b\u8bd5map\u7684\u8bfb\u53d6key\u7684\u6027\u80fd\uff0c\u7ed3\u679c\u9047\u5230\u65e0\u6cd5\u89e3\u7b54\u7684\u95ee\u9898\u3002"},"content":{"rendered":"<p>\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<p>\u5982\u679c\u6ce8\u91ca\u6389test2(),\u542f\u52a8test2_1()\uff0c\u5219test()\u6d88\u8017\u7684\u65f6\u95f4\u5927\u5e45\u51cf\u5c11\uff0c\u4e0d\u77e5\u539f\u56e0\u3002<\/p>\n<pre class=\"brush: bash; gutter: true\">import java.util.HashMap;\r\nimport java.util.IdentityHashMap;\r\nimport java.util.Map;\r\n\r\npublic class Test4 {\r\n\tprivate static Map&lt;Integer, Integer&gt; map1 = new HashMap&lt;Integer, Integer&gt;();\r\n\tprivate static Map&lt;String, String&gt; map2 = new HashMap&lt;String, String&gt;();\r\n\tprivate static Map&lt;String, String&gt; map3 = new IdentityHashMap&lt;String, String&gt;();\r\n\tprivate static String testKey = &quot;helloworld&quot;;\r\n\tprivate static long time;\r\n\tprivate static long time2;\r\n\tprivate static Integer a = 1500;\r\n\r\n\tpublic static void main(String[] args) {\r\n\t\tmap3.put(testKey, testKey);\r\n\t\tfor (int m = 1000; m &lt; 1010; m++) {\r\n\t\t\tmap1.put(m, m);\r\n\t\t\tmap2.put(&quot;&quot; + m, &quot;&quot; + m);\r\n\t\t\tmap3.put(&quot;&quot; + m, &quot;&quot; + m);\r\n\t\t}\r\n\t\tfor (int mm = 0; mm &lt; 100; mm++) {\r\n\t\t\ttest1();\r\n\t\t\ttest2();\r\n\t\t\t\/\/ test2_1();\r\n\t\t}\r\n\t}\r\n\r\n\tpublic static void test1() {\r\n\t\ttime = System.nanoTime();\r\n\t\tfor (int m = 0; m &lt; 1000000000; m++) {\r\n\t\t\tmap1.get(a);\r\n\t\t}\r\n\t\ttime2 = System.nanoTime();\r\n\t\tSystem.out.println(&quot;\u6570\u5b57\uff1a&quot; + (time2 - time));\r\n\t}\r\n\r\n\tpublic static void test2() {\r\n\t\ttime = System.nanoTime();\r\n\t\tfor (int m = 0; m &lt; 1000000000; m++) {\r\n\t\t\tmap2.get(&quot;hello&quot;);\r\n\t\t}\r\n\t\ttime2 = System.nanoTime();\r\n\t\tSystem.out.println(&quot;\u5b57\u7b26:&quot; + (time2 - time));\r\n\t}\r\n\r\n\tpublic static void test2_1() {\r\n\t\ttime = System.nanoTime();\r\n\t\tfor (int m = 0; m &lt; 1000000000; m++) {\r\n\t\t\tmap2.get(&quot;hello222222222222222222222222222222222222222222222222222222222222222222222222222222222222222&quot;);\r\n\t\t}\r\n\t\ttime2 = System.nanoTime();\r\n\t\tSystem.out.println(&quot;\u5b57\u7b26:&quot; + (time2 - time));\r\n\t}\r\n\r\n\tpublic static void test3() {\r\n\t\ttime = System.nanoTime();\r\n\t\tfor (int m = 0; m &lt; 1000000000; m++) {\r\n\t\t\tmap3.get(testKey);\r\n\t\t}\r\n\t\ttime2 = System.nanoTime();\r\n\t\tSystem.out.println(&quot;\u5b57\u7b263:&quot; + (time2 - time));\r\n\t}\r\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u4ee3\u7801\u5982\u4e0b\uff1a \u5982\u679c\u6ce8\u91ca\u6389test2(),\u542f\u52a8test2_1()\uff0c\u5219test()\u6d88\u8017 &hellip;<\/p>\n<p class=\"read-more\"><a href=\"https:\/\/blog.zhukunqian.com\/?p=1003\">\u7ee7\u7eed\u9605\u8bfb &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[24],"tags":[],"_links":{"self":[{"href":"https:\/\/blog.zhukunqian.com\/index.php?rest_route=\/wp\/v2\/posts\/1003"}],"collection":[{"href":"https:\/\/blog.zhukunqian.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.zhukunqian.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.zhukunqian.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.zhukunqian.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1003"}],"version-history":[{"count":2,"href":"https:\/\/blog.zhukunqian.com\/index.php?rest_route=\/wp\/v2\/posts\/1003\/revisions"}],"predecessor-version":[{"id":1006,"href":"https:\/\/blog.zhukunqian.com\/index.php?rest_route=\/wp\/v2\/posts\/1003\/revisions\/1006"}],"wp:attachment":[{"href":"https:\/\/blog.zhukunqian.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1003"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.zhukunqian.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1003"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.zhukunqian.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1003"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}