{"id":634,"date":"2018-03-01T11:27:10","date_gmt":"2018-03-01T03:27:10","guid":{"rendered":"http:\/\/prayerlaputa.com\/?p=634"},"modified":"2019-09-01T11:28:14","modified_gmt":"2019-09-01T03:28:14","slug":"java%e4%b8%adlist%e6%95%b0%e6%8d%ae%e5%90%88%e5%b9%b6%e4%b8%8e%e5%8e%bb%e9%87%8d","status":"publish","type":"post","link":"http:\/\/prayerlaputa.com\/?p=634","title":{"rendered":"java\u4e2dList\u6570\u636e\u5408\u5e76\u4e0e\u53bb\u91cd"},"content":{"rendered":"<h1 id=\"%E5%8D%95%E4%B8%AAlist%E6%95%B0%E6%8D%AE%E5%8E%BB%E9%87%8D\" class=\"mume-header\">\u5355\u4e2aList\u6570\u636e\u53bb\u91cd<\/h1>\n<p>\u601d\u8def\uff1a\u5229\u7528HashSet<br \/>\n\u4ee3\u7801\uff1a<\/p>\n<pre class=\"language-\" data-role=\"codeBlock\" data-info=\"\"><code>        List&lt;String&gt; list = new ArrayList&lt;&gt;();\r\n        list.add(\"a\");\r\n        list.add(\"b\");\r\n        list.add(\"c\");\r\n        list.add(\"c\");\r\n        list.add(\"c\");\r\n        for (String string : list) {\r\n            System.out.println(string);\r\n        }\r\n        System.out.println(\"=============================\");\r\n        \/\/\u8f6c\u6210set\r\n        List&lt;String&gt; listWithoutDup = new ArrayList&lt;&gt;(new HashSet&lt;&gt;(list));\r\n        for (String str : listWithoutDup) {\r\n            System.out.println(str);\r\n        }\r\n<\/code><\/pre>\n<p><!--more--><\/p>\n<h1 id=\"%E5%A4%9A%E4%B8%AAlist%E5%90%88%E5%B9%B6%E6%95%B0%E6%8D%AE%E5%8E%BB%E9%87%8D\" class=\"mume-header\">\u591a\u4e2aList\u5408\u5e76\uff0c\u6570\u636e\u53bb\u91cd<\/h1>\n<h2 id=\"java-8-%E4%B9%8B%E5%89%8D\" class=\"mume-header\">java 8 \u4e4b\u524d<\/h2>\n<p>\u601d\u8def\uff1a<\/p>\n<ol>\n<li>list1.removeAll(list2)<\/li>\n<li>list1.addAll(list2)<br \/>\n\u4ee3\u7801<\/li>\n<\/ol>\n<pre class=\"language-\" data-role=\"codeBlock\" data-info=\"\"><code>public static void main(String[] args) {\r\n        List&lt;String&gt; list = new ArrayList&lt;&gt;();\r\n        List&lt;String&gt; list2 = new ArrayList&lt;&gt;();\r\n        list.add(\"a\");\r\n        list.add(\"b\");\r\n        list.add(\"c\");\r\n        list.add(\"c\");\r\n        list2.add(\"a\");\r\n        list2.add(\"e\");\r\n        list2.add(\"e\");\r\n        list2.add(\"g\");\r\n        list2.add(\"g\");\r\n        for (String string : list) {\r\n            System.out.println(string);\r\n        }\r\n         \/\/\u6b64\u5904\u6307\u7684\u662f\u5c06\u4e0elist2\u91cd\u590d\u7684\u5220\u9664\r\n        list.removeAll(list2);\r\n        \/\/\u6b64\u5904\u6307\u52a0\u4e0alist2\r\n        list.addAll(list2);\r\n        System.out.println(\"=============================\");\r\n        for (String string : list) {\r\n            System.out.println(string);\r\n        }\r\n    }\r\n<\/code><\/pre>\n<h2 id=\"java-8%E4%BB%A5%E5%8F%8A%E6%9B%B4%E9%AB%98%E7%89%88%E6%9C%AClambda%E8%A1%A8%E8%BE%BE%E5%BC%8F\" class=\"mume-header\">java 8\u4ee5\u53ca\u66f4\u9ad8\u7248\u672c\uff1alambda\u8868\u8fbe\u5f0f<\/h2>\n<pre class=\"language-\" data-role=\"codeBlock\" data-info=\"\"><code>List&lt;String&gt; result = Stream.of(Lists.newArrayList(\"1\", \"1\", \"3\"), Lists.newArrayList(\"1\", \"2\"))\r\n  .flatMap(Collection::stream).distinct().collect(Collectors.toList());\r\n<\/code><\/pre>\n<p><strong>\u4ee3\u7801\u5f88\u4f18\u96c5\uff0c\u4f46\u662f\u8981\u5408\u5e76\u7684list\u5185\u5143\u7d20\u662f\u5bf9\u8c61\u9700\u8981equals\u548chashcode\u65b9\u6cd5<\/strong><\/p>\n<p>\u53c2\u8003\u8d44\u6599\uff1a<\/p>\n<ul>\n<li><a href=\"https:\/\/blog.csdn.net\/SongJingzhou\/article\/details\/94389577\">Java8 \u5408\u5e76list\u5e76\u53bb\u91cd<\/a><\/li>\n<li><a href=\"https:\/\/blog.csdn.net\/WYpersist\/article\/details\/80010129\">java List\u5408\u5e76\u548c\u53bb\u91cd\u7684\u4f8b\u5b50<\/a><\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5355\u4e2aList\u6570\u636e\u53bb\u91cd \u601d\u8def\uff1a\u5229\u7528HashSet \u4ee3\u7801\uff1a List&lt;String&gt; list = n <a href='http:\/\/prayerlaputa.com\/?p=634' class='excerpt-more'>[&#8230;]<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0},"categories":[6,12],"tags":[73],"_links":{"self":[{"href":"http:\/\/prayerlaputa.com\/index.php?rest_route=\/wp\/v2\/posts\/634"}],"collection":[{"href":"http:\/\/prayerlaputa.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/prayerlaputa.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/prayerlaputa.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/prayerlaputa.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=634"}],"version-history":[{"count":3,"href":"http:\/\/prayerlaputa.com\/index.php?rest_route=\/wp\/v2\/posts\/634\/revisions"}],"predecessor-version":[{"id":637,"href":"http:\/\/prayerlaputa.com\/index.php?rest_route=\/wp\/v2\/posts\/634\/revisions\/637"}],"wp:attachment":[{"href":"http:\/\/prayerlaputa.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=634"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/prayerlaputa.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=634"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/prayerlaputa.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=634"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}