{"id":38686,"date":"2024-11-26T13:08:23","date_gmt":"2024-11-26T05:08:23","guid":{"rendered":"https:\/\/fwq.ai\/blog\/38686\/"},"modified":"2024-11-26T13:08:23","modified_gmt":"2024-11-26T05:08:23","slug":"java-%e6%80%8e%e4%b9%88%e5%af%b9%e4%ba%8c%e7%bb%b4%e6%95%b0%e7%bb%84%e8%b5%8b%e5%80%bc","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/38686\/","title":{"rendered":"java \u600e\u4e48\u5bf9\u4e8c\u7ef4\u6570\u7ec4\u8d4b\u503c"},"content":{"rendered":"<blockquote><p>\n  java \u4e2d\u5bf9\u4e8c\u7ef4\u6570\u7ec4\u8fdb\u884c\u8d4b\u503c\u7684\u65b9\u6cd5\u5305\u62ec\uff1a\u901a\u8fc7\u5d4c\u5957\u5faa\u73af\u3001\u4f7f\u7528\u6570\u7ec4\u5b57\u9762\u91cf\u3001\u904d\u5386\u5e76\u8bbe\u53c2\u6570\u4e3a\u503c\u3001\u4f7f\u7528 java 8 stream api\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/15\/2024111504550847399.jpg\" class=\"aligncenter\" title=\"java \u600e\u4e48\u5bf9\u4e8c\u7ef4\u6570\u7ec4\u8d4b\u503c\u63d2\u56fe\" alt=\"java \u600e\u4e48\u5bf9\u4e8c\u7ef4\u6570\u7ec4\u8d4b\u503c\u63d2\u56fe\" \/><\/p>\n<p><strong>Java \u5982\u4f55\u5bf9\u4e8c\u7ef4\u6570\u7ec4\u8d4b\u503c<\/strong><\/p>\n<p>\u5728 Java \u4e2d\uff0c\u4e8c\u7ef4\u6570\u7ec4\u662f\u4e00\u7ec4\u5143\u7d20\u7684\u6709\u5e8f\u96c6\u5408\uff0c\u6210\u884c\u548c\u5217\u3002\u8981\u5bf9\u4e8c\u7ef4\u6570\u7ec4\u8fdb\u884c\u8d4b\u503c\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u65b9\u6cd5\uff1a<\/p>\n<p><strong>\u4f7f\u7528\u5d4c\u5957\u5faa\u73af<\/strong><\/p>\n<p>\u8fd9\u662f\u5bf9\u4e8c\u7ef4\u6570\u7ec4\u8fdb\u884c\u8d4b\u503c\u6700\u5e38\u7528\u7684\u4e00\u79cd\u65b9\u6cd5\u3002\u4f7f\u7528\u4e24\u4e2a\u5d4c\u5957\u7684\u5faa\u73af\u6765\u8fed\u4ee3\u6570\u7ec4\u7684\u884c\u548c\u5217\uff0c\u5e76\u4e3a\u6bcf\u4e2a\u5143\u7d20\u8d4b\u503c\uff1a<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<pre>int[][] arr = new int[3][4]; \/\/ \u521b\u5efa\u4e00\u4e2a 3 \u884c 4 \u5217\u7684\u4e8c\u7ef4\u6570\u7ec4\n\n\/\/ \u4f7f\u7528\u5d4c\u5957\u5faa\u73af\u5bf9\u6570\u7ec4\u8d4b\u503c\nfor (int i = 0; i &lt; arr.length; i++) {\n    for (int j = 0; j &lt; arr[i].length; j++) {\n        arr[i][j] = i * j;\n    }\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u4f7f\u7528\u6570\u7ec4\u5b57\u9762\u91cf<\/strong><\/p>\n<p>\u8fd9\u79cd\u65b9\u6cd5\u9002\u7528\u4e8e\u5728\u58f0\u660e\u4e8c\u7ef4\u6570\u7ec4\u65f6\u76f4\u63a5\u8d4b\u503c\uff1a<\/p>\n<pre>int[][] arr = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u904d\u5386\u5e76\u5c06\u503c\u8bbe\u4e3a\u53c2\u6570<\/strong><\/p>\n<p>\u6b64\u65b9\u6cd5\u5141\u8bb8\u60a8\u5c06\u503c\u5206\u914d\u7ed9\u4e8c\u7ef4\u6570\u7ec4\u4e2d\u7684\u7279\u5b9a\u4f4d\u7f6e\uff1a<\/p>\n<pre>int[][] arr = new int[3][4];\n\n\/\/ \u4f7f\u7528 set() \u65b9\u6cd5\u4e3a\u6307\u5b9a\u7d22\u5f15\u5904\u7684\u5143\u7d20\u8d4b\u503c\narr[1][2] = 10;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u4f7f\u7528 Java 8 Stream API<\/strong><\/p>\n<p>Java 8 \u53ca\u66f4\u9ad8\u7248\u672c\u63d0\u4f9b\u4e86\u4e00\u79cd\u4f7f\u7528 Stream API \u5bf9\u4e8c\u7ef4\u6570\u7ec4\u8fdb\u884c\u8d4b\u503c\u7684\u4fbf\u6377\u65b9\u6cd5\uff1a<\/p>\n<pre>int[][] arr = new int[3][4];\n\n\/\/ \u4f7f\u7528 flatMap() \u548c map() \u5bf9\u5143\u7d20\u8fdb\u884c\u8d4b\u503c\nArrays.stream(arr).flatMap(Arrays::stream).map(value -&gt; value * 2).forEachOrdered(value -&gt; System.out.print(value + \" \"));<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u6839\u636e\u60a8\u7684\u7279\u5b9a\u8981\u6c42\uff0c\u60a8\u53ef\u4ee5\u9009\u62e9\u6700\u9002\u5408\u7684\u8d4b\u503c\u65b9\u6cd5\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fjava \u600e\u4e48\u5bf9\u4e8c\u7ef4\u6570\u7ec4\u8d4b\u503c\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\u5bf9\u4e8c\u7ef4\u6570\u7ec4\u8fdb\u884c\u8d4b\u503c\u7684\u65b9\u6cd5\u5305\u62ec\uff1a\u901a\u8fc7\u5d4c\u5957\u5faa\u73af\u3001\u4f7f\u7528\u6570\u7ec4\u5b57\u9762\u91cf\u3001\u904d\u5386\u5e76\u8bbe\u53c2\u6570\u4e3a\u503c\u3001\u4f7f\u7528 java 8 stream api\u3002 Java \u5982\u4f55\u5bf9\u4e8c\u7ef4\u6570\u7ec4\u8d4b\u503c \u5728 Java \u4e2d\uff0c\u4e8c\u7ef4\u6570\u7ec4\u662f\u4e00\u7ec4\u5143\u7d20\u7684\u6709\u5e8f\u96c6\u5408\uff0c\u6210\u884c\u548c\u5217\u3002\u8981\u5bf9\u4e8c\u7ef4\u6570\u7ec4\u8fdb\u884c\u8d4b\u503c\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u65b9\u6cd5\uff1a \u4f7f\u7528\u5d4c\u5957\u5faa\u73af \u8fd9\u662f\u5bf9\u4e8c\u7ef4\u6570\u7ec4\u8fdb\u884c\u8d4b\u503c\u6700\u5e38\u7528\u7684\u4e00\u79cd\u65b9\u6cd5\u3002\u4f7f\u7528\u4e24\u4e2a\u5d4c\u5957\u7684\u5faa\u73af\u6765\u8fed\u4ee3\u6570\u7ec4\u7684\u884c\u548c\u5217\uff0c\u5e76\u4e3a\u6bcf\u4e2a\u5143\u7d20\u8d4b\u503c\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b int[][] arr = new int[3][4]; \/\/ \u521b\u5efa\u4e00\u4e2a 3 \u884c 4 \u5217\u7684\u4e8c\u7ef4\u6570\u7ec4 \/\/ \u4f7f\u7528\u5d4c\u5957\u5faa\u73af\u5bf9\u6570\u7ec4\u8d4b\u503c for (int i = 0; i &lt; arr.length; i++) { for (int j = 0; j &lt; arr[i].length; j++) { arr[i][j] = i * j; } } \u767b\u5f55\u540e\u590d\u5236 [&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-38686","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/38686","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=38686"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/38686\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=38686"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=38686"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=38686"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}