{"id":64848,"date":"2025-05-03T11:57:04","date_gmt":"2025-05-03T03:57:04","guid":{"rendered":"https:\/\/fwq.ai\/blog\/64848\/"},"modified":"2025-05-03T11:57:04","modified_gmt":"2025-05-03T03:57:04","slug":"java-stream-%e6%93%8d%e4%bd%9c%e4%b8%ad%ef%bc%8c%e6%b3%9b%e5%9e%8b%e4%b8%ba%e4%bd%95%e5%bf%85%e4%b8%8d%e5%8f%af%e5%b0%91%ef%bc%9f-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/64848\/","title":{"rendered":"Java Stream \u64cd\u4f5c\u4e2d\uff0c\u6cdb\u578b\u4e3a\u4f55\u5fc5\u4e0d\u53ef\u5c11\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173080802338870.jpg\" class=\"aligncenter\" title=\"Java Stream \u64cd\u4f5c\u4e2d\uff0c\u6cdb\u578b\u4e3a\u4f55\u5fc5\u4e0d\u53ef\u5c11\uff1f\u63d2\u56fe\" alt=\"Java Stream \u64cd\u4f5c\u4e2d\uff0c\u6cdb\u578b\u4e3a\u4f55\u5fc5\u4e0d\u53ef\u5c11\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>java stream \u6cdb\u578b\u4e3a\u4f55\u5fc5\u8981\uff1a\u907f\u514d\u7c7b\u578b\u64e6\u9664<\/strong><\/p>\n<p>java \u4e2d\u7684\u6cdb\u578b\u673a\u5236\u53ef\u786e\u4fdd\u5728\u7f16\u8bd1\u65f6\u6307\u5b9a\u7c7b\u578b\uff0c\u9632\u6b62\u8fd0\u884c\u65f6\u7684\u7c7b\u578b\u64e6\u9664\u3002\u5f53\u6cdb\u578b\u5728\u96c6\u5408\u4e2d\u4e0d\u6307\u5b9a\u65f6\uff0c\u4f1a\u5bfc\u81f4\u6d41\u64cd\u4f5c\u4e2d\u7684\u5143\u7d20\u7c7b\u578b\u65e0\u6cd5\u8bc6\u522b\u3002<\/p>\n<p>\u4f8b\u5982\uff0c\u4ee5\u4e0b\u4ee3\u7801\u56e0\u5217\u8868\u7f3a\u5c11\u6cdb\u578b\u800c\u5bfc\u81f4\u7c7b\u578b\u64e6\u9664\uff1a<\/p>\n<pre>List list = new ArrayList();\nlist.add(\"aaa\");\n\nlist.stream().map(a -&gt; a.toString())\n                .filter(a -&gt; a);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u5982\u679c list \u6ca1\u6709\u6cdb\u578b\uff0c\u7f16\u8bd1\u5668\u5c06\u63a8\u65ad\u5176\u7c7b\u578b\u4e3a list\u3002\u5bfc\u81f4\u4ee5\u4e0b\u95ee\u9898\uff1a<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<ul>\n<li> <strong>\u6d41\u64cd\u4f5c\u7684\u7c7b\u578b\u8bc6\u522b\u6df7\u4e71\uff1a<\/strong>map \u64cd\u4f5c\u7684\u9884\u671f\u7c7b\u578b\u4e3a string\uff0c\u4f46\u7531\u4e8e\u5217\u8868\u7c7b\u578b\u4e3a object\uff0cmap \u64cd\u4f5c\u5c06\u6267\u884c tostring() \u64cd\u4f5c\uff0c\u8fd4\u56de object \u7c7b\u578b\u7684\u5b57\u7b26\u4e32\u3002<\/li>\n<li> <strong>\u8fc7\u6ee4\u5668\u7684\u7c7b\u578b\u68c0\u67e5\u5931\u8d25\uff1a<\/strong>filter \u64cd\u4f5c\u5668\u671f\u671b\u53c2\u6570\u4e3a string \u7c7b\u578b\uff0c\u4f46\u7531\u4e8e\u6d41\u4e2d\u5143\u7d20\u7c7b\u578b\u4e3a object\uff0c\u5bfc\u81f4\u8fc7\u6ee4\u5668\u68c0\u67e5\u5931\u8d25\u3002<\/li>\n<\/ul>\n<p>\u6cdb\u578b\u4e0d\u6307\u5b9a\u7684\u539f\u56e0\u53ef\u4ee5\u8ffd\u6eaf\u5230\u8fd0\u884c\u65f6\u7684\u7c7b\u578b\u64e6\u9664\u673a\u5236\u3002\u5728\u7f16\u8bd1\u671f\u95f4\uff0c\u6cdb\u578b\u4fe1\u606f\u7528\u4e8e\u9a8c\u8bc1\u7c7b\u578b\u5b89\u5168\u6027\u548c\u63d0\u4f9b\u7c7b\u578b\u63d0\u793a\u3002\u4f46\u662f\uff0c\u5728\u8fd0\u884c\u65f6\uff0c\u6cdb\u578b\u4fe1\u606f\u4f1a\u88ab\u64e6\u9664\uff0c\u8fd9\u610f\u5473\u7740\u6240\u6709\u6cdb\u578b\u90fd\u5c06\u53d8\u6210 object \u7c7b\u578b\u3002<\/p>\n<p>\u56e0\u6b64\uff0c\u4e3a\u4e86\u907f\u514d\u7c7b\u578b\u64e6\u9664\u5e26\u6765\u7684\u95ee\u9898\u5e76\u786e\u4fdd\u6d41\u64cd\u4f5c\u7684\u7c7b\u578b\u5b89\u5168\uff0c\u9700\u8981\u5728\u521b\u5efa\u96c6\u5408\u65f6\u6307\u5b9a\u6cdb\u578b\u7c7b\u578b\u3002\u8fd9\u6837\uff0c\u7f16\u8bd1\u5668\u53ef\u4ee5\u5f3a\u5236\u6267\u884c\u7c7b\u578b\u68c0\u67e5\u5e76\u9632\u6b62\u4e0d\u5b89\u5168\u7684\u8f6c\u6362\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fJava Stream \u64cd\u4f5c\u4e2d\uff0c\u6cdb\u578b\u4e3a\u4f55\u5fc5\u4e0d\u53ef\u5c11\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8IDCBABY\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>java stream \u6cdb\u578b\u4e3a\u4f55\u5fc5\u8981\uff1a\u907f\u514d\u7c7b\u578b\u64e6\u9664 java \u4e2d\u7684\u6cdb\u578b\u673a\u5236\u53ef\u786e\u4fdd\u5728\u7f16\u8bd1\u65f6\u6307\u5b9a\u7c7b\u578b\uff0c\u9632\u6b62\u8fd0\u884c\u65f6\u7684\u7c7b\u578b\u64e6\u9664\u3002\u5f53\u6cdb\u578b\u5728\u96c6\u5408\u4e2d\u4e0d\u6307\u5b9a\u65f6\uff0c\u4f1a\u5bfc\u81f4\u6d41\u64cd\u4f5c\u4e2d\u7684\u5143\u7d20\u7c7b\u578b\u65e0\u6cd5\u8bc6\u522b\u3002 \u4f8b\u5982\uff0c\u4ee5\u4e0b\u4ee3\u7801\u56e0\u5217\u8868\u7f3a\u5c11\u6cdb\u578b\u800c\u5bfc\u81f4\u7c7b\u578b\u64e6\u9664\uff1a List list = new ArrayList(); list.add(&#8220;aaa&#8221;); list.stream().map(a -&gt; a.toString()) .filter(a -&gt; a); \u767b\u5f55\u540e\u590d\u5236 \u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u5982\u679c list \u6ca1\u6709\u6cdb\u578b\uff0c\u7f16\u8bd1\u5668\u5c06\u63a8\u65ad\u5176\u7c7b\u578b\u4e3a list\u3002\u5bfc\u81f4\u4ee5\u4e0b\u95ee\u9898\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b \u6d41\u64cd\u4f5c\u7684\u7c7b\u578b\u8bc6\u522b\u6df7\u4e71\uff1amap \u64cd\u4f5c\u7684\u9884\u671f\u7c7b\u578b\u4e3a string\uff0c\u4f46\u7531\u4e8e\u5217\u8868\u7c7b\u578b\u4e3a object\uff0cmap \u64cd\u4f5c\u5c06\u6267\u884c tostring() \u64cd\u4f5c\uff0c\u8fd4\u56de object \u7c7b\u578b\u7684\u5b57\u7b26\u4e32\u3002 \u8fc7\u6ee4\u5668\u7684\u7c7b\u578b\u68c0\u67e5\u5931\u8d25\uff1afilter \u64cd\u4f5c\u5668\u671f\u671b\u53c2\u6570\u4e3a string \u7c7b\u578b\uff0c\u4f46\u7531\u4e8e\u6d41\u4e2d\u5143\u7d20\u7c7b\u578b\u4e3a object\uff0c\u5bfc\u81f4\u8fc7\u6ee4\u5668\u68c0\u67e5\u5931\u8d25\u3002 \u6cdb\u578b\u4e0d\u6307\u5b9a\u7684\u539f\u56e0\u53ef\u4ee5\u8ffd\u6eaf\u5230\u8fd0\u884c\u65f6\u7684\u7c7b\u578b\u64e6\u9664\u673a\u5236\u3002\u5728\u7f16\u8bd1\u671f\u95f4\uff0c\u6cdb\u578b\u4fe1\u606f\u7528\u4e8e\u9a8c\u8bc1\u7c7b\u578b\u5b89\u5168\u6027\u548c\u63d0\u4f9b\u7c7b\u578b\u63d0\u793a\u3002\u4f46\u662f\uff0c\u5728\u8fd0\u884c\u65f6\uff0c\u6cdb\u578b\u4fe1\u606f\u4f1a\u88ab\u64e6\u9664\uff0c\u8fd9\u610f\u5473\u7740\u6240\u6709\u6cdb\u578b\u90fd\u5c06\u53d8\u6210 object \u7c7b\u578b\u3002 \u56e0\u6b64\uff0c\u4e3a\u4e86\u907f\u514d\u7c7b\u578b\u64e6\u9664\u5e26\u6765\u7684\u95ee\u9898\u5e76\u786e\u4fdd\u6d41\u64cd\u4f5c\u7684\u7c7b\u578b\u5b89\u5168\uff0c\u9700\u8981\u5728\u521b\u5efa\u96c6\u5408\u65f6\u6307\u5b9a\u6cdb\u578b\u7c7b\u578b\u3002\u8fd9\u6837\uff0c\u7f16\u8bd1\u5668\u53ef\u4ee5\u5f3a\u5236\u6267\u884c\u7c7b\u578b\u68c0\u67e5\u5e76\u9632\u6b62\u4e0d\u5b89\u5168\u7684\u8f6c\u6362\u3002 \u4ee5\u4e0a\u5c31\u662fJava Stream \u64cd\u4f5c\u4e2d\uff0c\u6cdb\u578b\u4e3a\u4f55\u5fc5\u4e0d\u53ef\u5c11\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8IDCBABY\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-64848","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/64848","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=64848"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/64848\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=64848"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=64848"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=64848"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}