{"id":39214,"date":"2024-11-26T10:54:24","date_gmt":"2024-11-26T02:54:24","guid":{"rendered":"https:\/\/fwq.ai\/blog\/39214\/"},"modified":"2024-11-26T10:54:24","modified_gmt":"2024-11-26T02:54:24","slug":"java%e6%80%8e%e4%b9%88%e8%ae%a9%e6%95%b0%e7%bb%84%e9%87%8c%e7%9a%84%e5%80%bc%e7%9b%b8%e5%8a%a0","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/39214\/","title":{"rendered":"java\u600e\u4e48\u8ba9\u6570\u7ec4\u91cc\u7684\u503c\u76f8\u52a0"},"content":{"rendered":"<blockquote><p>\n  java \u4e2d\u6570\u7ec4\u6c42\u548c\u7684\u65b9\u6cd5\uff1a\u4f7f\u7528 foreach \u65b9\u6cd5\uff1a\u8fed\u4ee3\u6570\u7ec4\uff0c\u5c06\u6bcf\u4e2a\u503c\u6dfb\u52a0\u5230\u7d2f\u52a0\u548c\u4e2d\u3002\u4f7f\u7528\u6d41 api\uff1a\u521b\u5efa\u6574\u6570\u6d41\u5e76\u4f7f\u7528 sum() \u65b9\u6cd5\u6c42\u548c\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/16\/2024111605244090428.jpg\" class=\"aligncenter\" title=\"java\u600e\u4e48\u8ba9\u6570\u7ec4\u91cc\u7684\u503c\u76f8\u52a0\u63d2\u56fe\" alt=\"java\u600e\u4e48\u8ba9\u6570\u7ec4\u91cc\u7684\u503c\u76f8\u52a0\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u5728 Java \u4e2d\u8ba9\u6570\u7ec4\u91cc\u7684\u503c\u76f8\u52a0<\/strong><\/p>\n<p>\u5728 Java \u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u6570\u7ec4\u7684 forEach \u65b9\u6cd5\u6216\u6d41 API \u6765\u8ba1\u7b97\u6570\u7ec4\u4e2d\u6240\u6709\u5143\u7d20\u7684\u603b\u548c\u3002<\/p>\n<p><strong>\u4f7f\u7528 forEach \u65b9\u6cd5\uff1a<\/strong><\/p>\n<pre>int[] numbers = {1, 2, 3, 4, 5};\nint sum = 0;\nfor (int number : numbers) {\n    sum += number;\n}\nSystem.out.println(\"Sum: \" + sum);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u4f7f\u7528\u6d41 API\uff1a<\/strong><\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<pre>int[] numbers = {1, 2, 3, 4, 5};\nint sum = IntStream.of(numbers).sum();\nSystem.out.println(\"Sum: \" + sum);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u8be6\u7ec6\u89e3\u91ca\uff1a<\/strong><\/p>\n<p><strong>forEach \u65b9\u6cd5\uff1a<\/strong><\/p>\n<ul>\n<li>\u4f7f\u7528 forEach \u6570\u7ec4\u65b9\u6cd5\u904d\u5386\u6570\u7ec4\u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\u3002<\/li>\n<li>\u5728\u6bcf\u6b21\u8fed\u4ee3\u4e2d\uff0c\u5c06\u5f53\u524d\u5143\u7d20\u6dfb\u52a0\u5230\u7d2f\u52a0\u548c sum \u4e2d\u3002<\/li>\n<li>\u6700\u540e\uff0c\u6253\u5370\u51fa\u8ba1\u7b97\u51fa\u7684\u603b\u548c\u3002<\/li>\n<\/ul>\n<p><strong>\u6d41 API\uff1a<\/strong><\/p>\n<ul>\n<li>\u4f7f\u7528 IntStream.of(numbers) \u521b\u5efa\u4e00\u4e2a\u6574\u6570\u6d41\uff0c\u5176\u4e2d\u5305\u542b\u6570\u7ec4\u4e2d\u7684\u503c\u3002<\/li>\n<li>\u4f7f\u7528 sum() \u65b9\u6cd5\u5bf9\u6d41\u4e2d\u7684\u6240\u6709\u503c\u6c42\u548c\u3002<\/li>\n<li>\u6700\u540e\uff0c\u6253\u5370\u51fa\u8ba1\u7b97\u51fa\u7684\u603b\u548c\u3002<\/li>\n<\/ul>\n<p>\u8fd9\u4e24\u79cd\u65b9\u6cd5\u90fd\u53ef\u4ee5\u6709\u6548\u5730\u8ba1\u7b97\u6570\u7ec4\u4e2d\u503c\u7684\u603b\u548c\uff0c\u4f46\u662f\u6d41 API \u901a\u5e38\u88ab\u8ba4\u4e3a\u66f4\u52a0\u7b80\u6d01\u548c\u9ad8\u6548\uff0c\u5c24\u5176\u662f\u5bf9\u4e8e\u5927\u578b\u6570\u7ec4\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fjava\u600e\u4e48\u8ba9\u6570\u7ec4\u91cc\u7684\u503c\u76f8\u52a0\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>java \u4e2d\u6570\u7ec4\u6c42\u548c\u7684\u65b9\u6cd5\uff1a\u4f7f\u7528 foreach \u65b9\u6cd5\uff1a\u8fed\u4ee3\u6570\u7ec4\uff0c\u5c06\u6bcf\u4e2a\u503c\u6dfb\u52a0\u5230\u7d2f\u52a0\u548c\u4e2d\u3002\u4f7f\u7528\u6d41 api\uff1a\u521b\u5efa\u6574\u6570\u6d41\u5e76\u4f7f\u7528 sum() \u65b9\u6cd5\u6c42\u548c\u3002 \u5982\u4f55\u5728 Java \u4e2d\u8ba9\u6570\u7ec4\u91cc\u7684\u503c\u76f8\u52a0 \u5728 Java \u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u6570\u7ec4\u7684 forEach \u65b9\u6cd5\u6216\u6d41 API \u6765\u8ba1\u7b97\u6570\u7ec4\u4e2d\u6240\u6709\u5143\u7d20\u7684\u603b\u548c\u3002 \u4f7f\u7528 forEach \u65b9\u6cd5\uff1a int[] numbers = {1, 2, 3, 4, 5}; int sum = 0; for (int number : numbers) { sum += number; } System.out.println(&#8220;Sum: &#8221; + sum); \u767b\u5f55\u540e\u590d\u5236 \u4f7f\u7528\u6d41 API\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b int[] numbers = {1, 2, [&hellip;]<\/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-39214","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/39214","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=39214"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/39214\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=39214"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=39214"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=39214"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}