{"id":1431,"date":"2022-11-03T23:02:13","date_gmt":"2022-11-03T15:02:13","guid":{"rendered":"https:\/\/qaqaq.top\/?p=1431"},"modified":"2022-11-27T12:39:44","modified_gmt":"2022-11-27T04:39:44","slug":"java%e5%86%85%e7%bd%ae%e7%9a%84%e5%87%bd%e6%95%b0%e5%bc%8f%e6%8e%a5%e5%8f%a3%e4%bb%8b%e7%bb%8d%e5%8f%8a%e4%bd%bf%e7%94%a8%e4%b8%be%e4%be%8b","status":"publish","type":"post","link":"https:\/\/qaqaq.top\/?p=1431","title":{"rendered":"Java\u5185\u7f6e\u7684\u51fd\u6570\u5f0f\u63a5\u53e3\u4ecb\u7ecd\u53ca\u4f7f\u7528\u4e3e\u4f8b"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>package top.qaqaq.java.P672;\r\n\r\nimport org.junit.jupiter.api.Test;\r\n\r\nimport java.util.ArrayList;\r\nimport java.util.Arrays;\r\nimport java.util.List;\r\nimport java.util.function.Consumer;\r\nimport java.util.function.Predicate;\r\n\r\n\/**\r\n * @author RichieZhang\r\n * @create 2022-11-03 \u4e0b\u5348 4:33\r\n *\r\n * \u6d88\u8d39\u578b\u63a5\u53e3 Consumer&lt;T>        void accept(T t)\r\n * \u4f9b\u7ed9\u578b\u63a5\u53e3 Supplier&lt;T>        T get()\r\n * \u51fd\u6570\u578b\u63a5\u53e3 Function&lt;T,R>      R apply(T t)\r\n * \u65ad\u5b9a\u578b\u63a5\u53e3 Predicate&lt;T>       boolean test(T t)\r\n *\r\n *\r\n *\/\r\npublic class LambdaTest2 {\r\n\r\n    @Test\r\n    public void test1(){\r\n\r\n        happyTime(500, new Consumer&lt;Double>() {\r\n            @Override\r\n            public void accept(Double aDouble) {\r\n                System.out.println(\"\u5b66\u4e60\u592a\u7d2f\u4e86\uff0c\u53bb\u5929\u4e0a\u4eba\u95f4\u4e70\u4e86\u74f6\u77ff\u6cc9\u6c34\uff0c\u4ef7\u683c\u4e3a\uff1a\" + aDouble);\r\n            }\r\n        });\r\n\r\n        System.out.println(\"*******************************\");\r\n\r\n        happyTime(400,money -> System.out.println(\"\u5b66\u4e60\u592a\u7d2f\u4e86\uff0c\u53bb\u5929\u4e0a\u4eba\u95f4\u559d\u4e86\u53e3\u6c34\uff0c\u4ef7\u683c\u4e3a\uff1a\" + money));\r\n    }\r\n\r\n    public void happyTime(double money, Consumer&lt;Double> con){\r\n        con.accept(money);\r\n    }\r\n\r\n    @Test\r\n    public void test2(){\r\n\r\n        List&lt;String> list = Arrays.asList(\"\u5317\u4eac\",\"\u5357\u4eac\",\"\u5929\u6d25\",\"\u4e1c\u4eac\",\"\u897f\u4eac\",\"\u666e\u4eac\");\r\n        List&lt;String> filterStrs = filterString(list, new Predicate&lt;String>() {\r\n            @Override\r\n            public boolean test(String s) {\r\n                return s.contains(\"\u4eac\");\r\n            }\r\n        });\r\n\r\n        System.out.println(filterStrs);\r\n\r\n        List&lt;String> filterStrs1 = filterString(list,s -> s.contains(\"\u4eac\"));\r\n        System.out.println(filterStrs1);\r\n    }\r\n\r\n    \/\/\u6839\u636e\u7ed9\u5b9a\u7684\u89c4\u5219\uff0c\u8fc7\u6ee4\u96c6\u5408\u4e2d\u7684\u5b57\u7b26\u4e32\u3002\u6b64\u89c4\u5219\u7531Predicate\u7684\u65b9\u6cd5\u51b3\u5b9a\r\n    public List&lt;String> filterString(List&lt;String> list, Predicate&lt;String> pre){\r\n\r\n        ArrayList&lt;String> filterList = new ArrayList&lt;>();\r\n        for (String s : list) {\r\n            if(pre.test(s)){\r\n                filterList.add(s);\r\n            }\r\n        }\r\n\r\n        return filterList;\r\n    }\r\n}\r\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[46],"class_list":["post-1431","post","type-post","status-publish","format-standard","hentry","category-java-code","tag-java"],"_links":{"self":[{"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts\/1431"}],"collection":[{"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1431"}],"version-history":[{"count":1,"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts\/1431\/revisions"}],"predecessor-version":[{"id":1432,"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts\/1431\/revisions\/1432"}],"wp:attachment":[{"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1431"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1431"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1431"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}