{"id":277578,"date":"2021-01-13T01:20:34","date_gmt":"2021-01-12T17:20:34","guid":{"rendered":"http:\/\/4563.org\/?p=277578"},"modified":"2021-01-13T01:20:34","modified_gmt":"2021-01-12T17:20:34","slug":"%e4%bb%8a%e5%a4%a9%e7%a2%b0%e5%88%b0%e7%9a%84%e4%b8%80%e4%b8%aa%e7%9a%84%e6%93%8d%e4%bd%9c%ef%bc%8c-%e5%a6%82%e6%9e%9c%e6%98%af%e5%90%8c%e4%b8%80%e4%b8%aa%e4%bd%9c%e8%80%85%ef%bc%8c%e5%81%87%e8%ae%be","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=277578","title":{"rendered":"\u4eca\u5929\u78b0\u5230\u7684\u4e00\u4e2a\u7684\u64cd\u4f5c\uff0c \u5982\u679c\u662f\u540c\u4e00\u4e2a\u4f5c\u8005\uff0c\u5047\u8bbe\u4e66\u540d\u662f\u4e00\u6837\u7684\u60c5\u51b5\u4e0b\uff0c\u5bf9\u5e94\u7684\u65e5\u671f\u4fee\u6539\u4e3a\u6307\u5b9a\u65e5\u671f\uff0c\u4f46\u662f\u6ca1\u6709\u5f04\u660e\u767d\uff0c\u4e3a\u4ec0\u4e48\u53ef\u4ee5\u8fd9\u4e48\u64cd\u4f5c\uff0c\u4e0b\u9762\u662f\u4f8b\u5b50:"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  \u4eca\u5929\u78b0\u5230\u7684\u4e00\u4e2a\u7684\u64cd\u4f5c\uff0c \u5982\u679c\u662f\u540c\u4e00\u4e2a\u4f5c\u8005\uff0c\u5047\u8bbe\u4e66\u540d\u662f\u4e00\u6837\u7684\u60c5\u51b5\u4e0b\uff0c\u5bf9\u5e94\u7684\u65e5\u671f\u4fee\u6539\u4e3a\u6307\u5b9a\u65e5\u671f\uff0c\u4f46\u662f\u6ca1\u6709\u5f04\u660e\u767d\uff0c\u4e3a\u4ec0\u4e48\u53ef\u4ee5\u8fd9\u4e48\u64cd\u4f5c\uff0c\u4e0b\u9762\u662f\u4f8b\u5b50:               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Gilgamesh7 <\/span>  <span><i><\/i> 1<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<pre><code> @Data @Builder public class Book {     private String name;     private String author;     private String day; }  @Slf4j public class Test {  public static void main(String[] args) {         Book book1 = Book.builder().name(\"Java\").author(\"a\").day(\"2020-01-01\").build();         Book book2 = Book.builder().name(\"Python\").author(\"b\").day(\"2020-06-01\").build();         Book book3 = Book.builder().name(\"PHP\").author(\"c\").day(\"2020-07-01\").build();         Book book4 = Book.builder().name(\"Java\").author(\"a\").day(\"2020-02-01\").build();         Map&lt;String, Book&gt; map = new HashMap&lt;&gt;();         List&lt;Book&gt; books = Arrays.asList(book1, book2, book3, book4);         List&lt;Book&gt; result = books.stream().map(x -&gt; {             if (map.containsKey(x.getAuthor())) {                 x.setDay(\"2020-05-01\");                 map.get(x.getAuthor()).setDay(\"2020-05-01\");             } else {                 map.put(x.getAuthor(), x);             }             return x;         }).collect(Collectors.toList());         log.info(JSON.toJSONString(result));     }  <\/code><\/pre>\n<pre><code>\u7ed3\u679c:    [{\"author\":\"a\",\"day\":\"2020-05-01\",\"name\":\"Java\"},     {\"author\":\"b\",\"day\":\"2020-06-01\",\"name\":\"Python\"},      {\"author\":\"c\",\"day\":\"2020-07-01\",\"name\":\"PHP\"},     {\"author\":\"a\",\"day\":\"2020-05-01\",\"name\":\"Java\"}]  <\/code><\/pre>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>6<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"4922587\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : jinhan13789991 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u7528 map key \u552f\u4e00\u7684\u7279\u6027\uff0c\u5224\u65ad\u6709\u6ca1\u6709\u91cd\u590d\u7684\u3002\u800c\u4e14\u8fd9\u4ee3\u7801\u6709\u95ee\u9898\uff0c\u53ea\u5224\u65ad\u4e86\u4f5c\u8005\uff0c\u6ca1\u6709\u5224\u65ad\u4e66\u540d\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4922588\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : Gilgamesh7 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @jinhan13789991 \u9898\u76ee\u6709\u5047\u8bbe\uff0c\u4e66\u540d\u662f\u4e00\u6837\u7684\uff1b\u5df2\u7ecf\u8fd4\u56de\u4e86 x \u5230\u96c6\u5408\u4e2d\u4e86\uff0c\u4f46\u662f\u540e\u9762\u53c8\u5bf9\u653e\u5165\u96c6\u5408\u7684 x \u7684\u65f6\u95f4\u8fdb\u884c\u4e86\u66f4\u65b0\uff0c\u8fd9\u91cc\u6709\u70b9\u4e0d\u592a\u6e05\u695a                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4922589\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : jinhan13789991 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @Gilgamesh7 \u4e0d\u5982\u5c1d\u8bd5\u5bf9\u6bcf\u884c\u4ee3\u7801\u8fdb\u884c\u6ce8\u91ca\uff0c\u7136\u540e\u53bb\u7406\u89e3\u603b\u4f53\u7684\u601d\u8def\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4922590\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : hello2060 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6709\u5565\u770b\u4e0d\u61c2\u7684\uff0cmap()\u6700\u540e\u8fd8\u662f\u8fd4\u56de\u4e86 x \u672c\u8eab\u554a\uff0c<\/p>\n<p>\u524d\u4e09\u4e2a\u8c03\u7528\u5206\u522b\u8fd4\u56de book1, book2, book3, \u7b2c\u56db\u4e2a\u5143\u7d20\u8fd0\u7b97\u7684\u65f6\u5019\uff0c\u5148\u6539\u53d8\u81ea\u5df1\u6307\u5411\u5bf9\u8c61\u7684\u65e5\u671f\uff0c\u7136\u540e\u6539\u53d8\u4e86 book1 \u6307\u5411\u5bf9\u8c61\u7684\u65e5\u671f\u3002<\/p>\n<p>\u6240\u4ee5\u6700\u540e\u8fd4\u56de book1, book2, book3, book4, 1 \u548c 4 \u7684\u65e5\u671f\u90fd\u53d8\u4e86\u554a                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4922591\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : lychs1998 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5982\u679c\u8fd9\u672c\u4e66\u4f5c\u8005\u6ca1\u88ab\u8bb0\u5f55\uff0c\u5219\u4e22\u8fdb map \u3002\u5982\u679c\u8fd9\u672c\u4e66\u4f5c\u8005\u88ab\u8bb0\u5f55\u4e86\uff0c\u90a3\u4e48\u628a\u8fd9\u672c\u4e66\u65f6\u95f4\u8fdb\u884c\u4fee\u6539\uff0c\u5e76\u4fee\u6539 map \u4e2d\u5b58\u5728\u5bf9\u8c61\u7684\u5c5e\u6027\u3002\u8fd9\u4e2a\u662f stream \u6d41\u91cc\u505a\u7684\u903b\u8f91\u3002<\/p>\n<p>\u81f3\u4e8e map \u91cc\u5b58\u5728\u7684 book \u4e3a\u4ec0\u4e48\u4f1a\u88ab\u8f93\u51fa\u5230 result \u91cc\uff0c\u6211\u89c9\u5f97\u53ef\u4ee5\u8fd9\u6837\u7406\u89e3\uff1a<br \/>1.map.put \u540e\u8f93\u5165\u7684\u5176\u5b9e\u662f book \u5bf9\u8c61\u7684\u5f15\u7528\uff0c\u800c\u4e0d\u662f\u4e00\u4e2a\u65b0\u7684\u5bf9\u8c61<br \/>2.map.get \u901a\u8fc7\u5bf9\u8c61\u7684\u5f15\u7528\u62ff\u5230\u4e86\u4e4b\u524d\u904d\u5386\u8fc7\u7684\u5bf9\u8c61\uff0c\u4fee\u6539\u4e86\u91cc\u9762\u7684\u503c<br \/>3.return x \u8fd4\u56de\u7684\u4e5f\u662f\u5bf9\u8c61\u7684\u5f15\u7528                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4922592\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : Gilgamesh7 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @lychs1998 \u611f\u8c22\uff0c\u89e3\u91ca\u7684\u5f88\u6e05\u695a\uff0c\u6211\u6ca1\u6709\u6ce8\u610f\u5230 book \u653e\u5230 map \u5176\u5b9e\u662f\u5bf9\u8c61\u7684\u5f15\u7528\uff0c\u5e76\u4e0d\u662f\u65b0\u5bf9\u8c61\uff0c\u611f\u8c22\u89e3\u7b54\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>\u4eca\u5929\u78b0\u5230\u7684\u4e00\u4e2a\u7684\u64cd\u4f5c\uff0c \u5982\u679c\u662f\u540c\u4e00&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/277578"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=277578"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/277578\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=277578"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=277578"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=277578"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}