{"id":64611,"date":"2025-05-03T12:23:10","date_gmt":"2025-05-03T04:23:10","guid":{"rendered":"https:\/\/fwq.ai\/blog\/64611\/"},"modified":"2025-05-03T12:23:10","modified_gmt":"2025-05-03T04:23:10","slug":"%e6%80%8e%e4%b9%88%e7%94%a8java%e6%b1%82%e4%b8%a4%e4%b8%aa%e6%95%b0%e7%bb%84%e4%b9%8b%e5%92%8c-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/64611\/","title":{"rendered":"\u600e\u4e48\u7528java\u6c42\u4e24\u4e2a\u6570\u7ec4\u4e4b\u548c"},"content":{"rendered":"<blockquote><p>\n  \u5728 java \u4e2d\uff0c\u6c42\u4e24\u4e2a\u6570\u7ec4\u4e4b\u548c\u6709\u4e24\u79cd\u65b9\u6cd5\uff1a\u4f7f\u7528\u6570\u7ec4\u64cd\u4f5c\uff0c\u9700\u8981\u4e24\u4e2a\u6570\u7ec4\u957f\u5ea6\u76f8\u7b49\u3002\u4f7f\u7528 java stream api\uff0c\u6570\u7ec4\u957f\u5ea6\u53ef\u4ee5\u4e0d\u540c\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/04\/2024110403334956965.jpg\" class=\"aligncenter\" title=\"\u600e\u4e48\u7528java\u6c42\u4e24\u4e2a\u6570\u7ec4\u4e4b\u548c\u63d2\u56fe\" alt=\"\u600e\u4e48\u7528java\u6c42\u4e24\u4e2a\u6570\u7ec4\u4e4b\u548c\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u4f7f\u7528 Java \u6c42\u4e24\u4e2a\u6570\u7ec4\u4e4b\u548c<\/strong><\/p>\n<p>\u5728 Java \u4e2d\u6c42\u4e24\u4e2a\u6570\u7ec4\u4e4b\u548c\u7684\u65b9\u6cd5\u6709\u4e24\u79cd\uff1a<\/p>\n<p><strong>1. \u4f7f\u7528\u6570\u7ec4\u64cd\u4f5c<\/strong><\/p>\n<pre>\/\/ \u6570\u7ec4 a \u548c b \u7684\u957f\u5ea6\u5fc5\u987b\u76f8\u7b49\nint[] a = {1, 2, 3};\nint[] b = {4, 5, 6};\nint[] sum = new int[a.length];\n\nfor (int i = 0; i &lt; a.length; i++) {\n    sum[i] = a[i] + b[i];\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>2. \u4f7f\u7528 Java Stream API<\/strong><\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<pre>\/\/ \u6570\u7ec4 a \u548c b \u7684\u957f\u5ea6\u53ef\u4ee5\u4e0d\u540c\nint[] a = {1, 2, 3};\nint[] b = {4, 5};\nint[] sum = new int[Math.max(a.length, b.length)];\n\nIntStream.range(0, Math.max(a.length, b.length))\n        .forEach(i -&gt; sum[i] = (i &lt; a.length ? a[i] : 0) + (i &lt; b.length ? b[i] : 0));<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u600e\u4e48\u7528java\u6c42\u4e24\u4e2a\u6570\u7ec4\u4e4b\u548c\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>\u5728 java \u4e2d\uff0c\u6c42\u4e24\u4e2a\u6570\u7ec4\u4e4b\u548c\u6709\u4e24\u79cd\u65b9\u6cd5\uff1a\u4f7f\u7528\u6570\u7ec4\u64cd\u4f5c\uff0c\u9700\u8981\u4e24\u4e2a\u6570\u7ec4\u957f\u5ea6\u76f8\u7b49\u3002\u4f7f\u7528 java stream api\uff0c\u6570\u7ec4\u957f\u5ea6\u53ef\u4ee5\u4e0d\u540c\u3002 \u5982\u4f55\u4f7f\u7528 Java \u6c42\u4e24\u4e2a\u6570\u7ec4\u4e4b\u548c \u5728 Java \u4e2d\u6c42\u4e24\u4e2a\u6570\u7ec4\u4e4b\u548c\u7684\u65b9\u6cd5\u6709\u4e24\u79cd\uff1a 1. \u4f7f\u7528\u6570\u7ec4\u64cd\u4f5c \/\/ \u6570\u7ec4 a \u548c b \u7684\u957f\u5ea6\u5fc5\u987b\u76f8\u7b49 int[] a = {1, 2, 3}; int[] b = {4, 5, 6}; int[] sum = new int[a.length]; for (int i = 0; i &lt; a.length; i++) { sum[i] = a[i] + b[i]; } \u767b\u5f55\u540e\u590d\u5236 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-64611","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/64611","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=64611"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/64611\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=64611"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=64611"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=64611"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}