{"id":630,"date":"2022-10-18T17:15:27","date_gmt":"2022-10-18T09:15:27","guid":{"rendered":"https:\/\/blog.lijiajia.top\/?p=630"},"modified":"2026-06-19T21:43:58","modified_gmt":"2026-06-19T13:43:58","slug":"%e9%9b%86%e5%90%88%e8%bd%acmap%ef%bc%8c%e9%87%8d%e5%a4%8dkey%e7%9a%84%e9%97%ae%e9%a2%98%ef%bc%9ajava-lang-illegalstateexception-duplicate-key-0","status":"publish","type":"post","link":"https:\/\/blog.ttwow.top\/?p=630","title":{"rendered":"\u96c6\u5408\u8f6cmap\uff0c\u91cd\u590dkey\u7684\u95ee\u9898\uff1ajava.lang.IllegalStateException: Duplicate key 0"},"content":{"rendered":"<p>java.lang.IllegalStateException: Duplicate key 0<\/p>\n<p><a href=\"https:\/\/blog.csdn.net\/qq_40366738\/article\/details\/114754348\">https:\/\/blog.csdn.net\/qq_40366738\/article\/details\/114754348<\/a><\/p>\n<p>\u96c6\u5408\u8f6cmap\uff0c\u91cd\u590dkey\u7684\u95ee\u9898<\/p>\n<pre><code class=\"language-java\">public class Test {\n    public static void main(String[] args) {\n        List&lt;Map.Entry&gt; list = new ArrayList&lt;&gt;();\n        for (int i = 0; i &lt; 3; i++) {\n            Map.Entry entry = new AbstractMap.SimpleEntry&lt;&gt;(1,i);\n            list.add(entry);\n        }\n        Map&lt;Object, Object&gt; map = list.stream().collect(\n                Collectors.toMap(\n                        Map.Entry::getKey,\n                        Map.Entry::getValue,\n                        \/\/\u4ee5\u6700\u540e\u4e00\u4e2a\u5143\u7d20\u4e3a\u51c6\uff0c\u66f4\u65b0\n                        \/\/(e1,e2) -&gt; e2\n                        \/\/\u4ee5\u7b2c\u4e00\u4e2a\u5143\u7d20\u4e3a\u51c6\uff0c\u4e0d\u66f4\u65b0\n                        (e1,e2) -&gt; e1\n                ));\n        System.out.println(map);\n    }\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>java.lang.IllegalStateException: Duplicate key 0 https: [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[134],"tags":[42],"class_list":["post-630","post","type-post","status-publish","format-standard","hentry","category-debug-troubleshooting","tag-java"],"_links":{"self":[{"href":"https:\/\/blog.ttwow.top\/index.php?rest_route=\/wp\/v2\/posts\/630","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.ttwow.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.ttwow.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.ttwow.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.ttwow.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=630"}],"version-history":[{"count":1,"href":"https:\/\/blog.ttwow.top\/index.php?rest_route=\/wp\/v2\/posts\/630\/revisions"}],"predecessor-version":[{"id":2170,"href":"https:\/\/blog.ttwow.top\/index.php?rest_route=\/wp\/v2\/posts\/630\/revisions\/2170"}],"wp:attachment":[{"href":"https:\/\/blog.ttwow.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=630"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ttwow.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=630"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ttwow.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=630"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}