{"id":38644,"date":"2024-11-26T16:15:12","date_gmt":"2024-11-26T08:15:12","guid":{"rendered":"https:\/\/fwq.ai\/blog\/38644\/"},"modified":"2024-11-26T16:15:12","modified_gmt":"2024-11-26T08:15:12","slug":"java%e6%80%8e%e4%b9%88%e5%b0%86%e5%87%a0%e7%bb%84%e6%95%b0%e5%ad%98%e5%85%a5%e6%95%b0%e7%bb%84%e4%b8%ad","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/38644\/","title":{"rendered":"java\u600e\u4e48\u5c06\u51e0\u7ec4\u6570\u5b58\u5165\u6570\u7ec4\u4e2d"},"content":{"rendered":"<blockquote><p>\n  \u5c06\u51e0\u7ec4\u6570\u5b58\u50a8\u5230 java \u6570\u7ec4\u4e2d\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u65b9\u6cd5\uff1a\u5229\u7528\u591a\u7ef4\u6570\u7ec4\u521b\u5efa\u5305\u542b\u591a\u4e2a\u6570\u7ec4\u7684\u4e8c\u7ef4\u6570\u7ec4\u3002\u4f7f\u7528\u6570\u7ec4\u5217\u8868\u521b\u5efa\u52a8\u6001\u5217\u8868\uff0c\u5e76\u9010\u4e00\u6dfb\u52a0\u6570\u7ec4\u3002\u5229\u7528\u6d41\u5f0f\u5904\u7406\u521b\u5efa\u5e76\u64cd\u4f5c\u6570\u636e\u7ed3\u6784\uff0c\u8f6c\u5316\u4e3a\u5177\u6709\u6240\u9700\u5f62\u72b6\u7684\u6570\u7ec4\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/15\/2024111504241746829.jpg\" class=\"aligncenter\" title=\"java\u600e\u4e48\u5c06\u51e0\u7ec4\u6570\u5b58\u5165\u6570\u7ec4\u4e2d\u63d2\u56fe\" alt=\"java\u600e\u4e48\u5c06\u51e0\u7ec4\u6570\u5b58\u5165\u6570\u7ec4\u4e2d\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u5c06\u51e0\u7ec4\u6570\u5b58\u5165 Java \u6570\u7ec4<\/strong><\/p>\n<p>\u4f7f\u7528 Java \u6570\u7ec4\u5b58\u50a8\u591a\u4e2a\u6570\u503c\u7ec4\uff0c\u6709\u4ee5\u4e0b\u51e0\u79cd\u65b9\u6cd5\uff1a<\/p>\n<p><strong>1. \u4f7f\u7528\u591a\u7ef4\u6570\u7ec4<\/strong><\/p>\n<p>\u591a\u7ef4\u6570\u7ec4\u5141\u8bb8\u60a8\u4f7f\u7528\u5355\u4e2a\u53d8\u91cf\u6765\u5b58\u50a8\u591a\u4e2a\u6570\u7ec4\u3002\u5bf9\u4e8e\u60a8\u7684\u60c5\u51b5\uff0c\u53ef\u4ee5\u4f7f\u7528\u4e8c\u7ef4\u6570\u7ec4\uff1a<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<pre>int[][] numbers = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd9\u5c06\u521b\u5efa\u4e00\u4e2a\u5305\u542b\u4e09\u4e2a\u6570\u7ec4\u7684\u4e8c\u7ef4\u6570\u7ec4\uff0c\u6bcf\u4e2a\u6570\u7ec4\u5305\u542b\u4e09\u4e2a\u6570\u5b57\u3002<\/p>\n<p><strong>2. \u4f7f\u7528\u6570\u7ec4\u5217\u8868<\/strong><\/p>\n<p>\u6570\u7ec4\u5217\u8868\u662f\u52a8\u6001\u6570\u7ec4\uff0c\u5141\u8bb8\u60a8\u5728\u9700\u8981\u65f6\u6dfb\u52a0\u6216\u79fb\u9664\u9879\u3002\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u8bed\u6cd5\u521b\u5efa\u6570\u7ec4\u5217\u8868\uff1a<\/p>\n<pre>List&lt;int[]&gt; numbers = new ArrayList&lt;&gt;();<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u7136\u540e\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528 add() \u65b9\u6cd5\u5c06\u6570\u7ec4\u6dfb\u52a0\u5230\u5217\u8868\u4e2d\uff1a<\/p>\n<pre>numbers.add(new int[]{1, 2, 3});\nnumbers.add(new int[]{4, 5, 6});\nnumbers.add(new int[]{7, 8, 9});<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>3. \u4f7f\u7528\u6d41\u5f0f\u5904\u7406<\/strong><\/p>\n<p>\u6d41\u5f0f\u5904\u7406\u63d0\u4f9b\u4e86\u4e00\u79cd\u7b80\u6d01\u7684\u65b9\u5f0f\u6765\u521b\u5efa\u548c\u64cd\u4f5c\u6570\u636e\u7ed3\u6784\u3002\u60a8\u53ef\u4ee5\u4f7f\u7528 IntStream \u6765\u521b\u5efa\u6570\u7ec4\uff1a<\/p>\n<pre>int[][] numbers = IntStream.range(1, 10)\n    .toArray()\n    .reshape(3, 3);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd9\u5c06\u521b\u5efa\u4e00\u4e2a 3&#215;3 \u4e8c\u7ef4\u6570\u7ec4\uff0c\u5176\u4e2d\u5305\u542b\u4ece 1 \u5230 9 \u7684\u6570\u5b57\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fjava\u600e\u4e48\u5c06\u51e0\u7ec4\u6570\u5b58\u5165\u6570\u7ec4\u4e2d\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>\u5c06\u51e0\u7ec4\u6570\u5b58\u50a8\u5230 java \u6570\u7ec4\u4e2d\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u65b9\u6cd5\uff1a\u5229\u7528\u591a\u7ef4\u6570\u7ec4\u521b\u5efa\u5305\u542b\u591a\u4e2a\u6570\u7ec4\u7684\u4e8c\u7ef4\u6570\u7ec4\u3002\u4f7f\u7528\u6570\u7ec4\u5217\u8868\u521b\u5efa\u52a8\u6001\u5217\u8868\uff0c\u5e76\u9010\u4e00\u6dfb\u52a0\u6570\u7ec4\u3002\u5229\u7528\u6d41\u5f0f\u5904\u7406\u521b\u5efa\u5e76\u64cd\u4f5c\u6570\u636e\u7ed3\u6784\uff0c\u8f6c\u5316\u4e3a\u5177\u6709\u6240\u9700\u5f62\u72b6\u7684\u6570\u7ec4\u3002 \u5982\u4f55\u5c06\u51e0\u7ec4\u6570\u5b58\u5165 Java \u6570\u7ec4 \u4f7f\u7528 Java \u6570\u7ec4\u5b58\u50a8\u591a\u4e2a\u6570\u503c\u7ec4\uff0c\u6709\u4ee5\u4e0b\u51e0\u79cd\u65b9\u6cd5\uff1a 1. \u4f7f\u7528\u591a\u7ef4\u6570\u7ec4 \u591a\u7ef4\u6570\u7ec4\u5141\u8bb8\u60a8\u4f7f\u7528\u5355\u4e2a\u53d8\u91cf\u6765\u5b58\u50a8\u591a\u4e2a\u6570\u7ec4\u3002\u5bf9\u4e8e\u60a8\u7684\u60c5\u51b5\uff0c\u53ef\u4ee5\u4f7f\u7528\u4e8c\u7ef4\u6570\u7ec4\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b int[][] numbers = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; \u767b\u5f55\u540e\u590d\u5236 \u8fd9\u5c06\u521b\u5efa\u4e00\u4e2a\u5305\u542b\u4e09\u4e2a\u6570\u7ec4\u7684\u4e8c\u7ef4\u6570\u7ec4\uff0c\u6bcf\u4e2a\u6570\u7ec4\u5305\u542b\u4e09\u4e2a\u6570\u5b57\u3002 2. \u4f7f\u7528\u6570\u7ec4\u5217\u8868 \u6570\u7ec4\u5217\u8868\u662f\u52a8\u6001\u6570\u7ec4\uff0c\u5141\u8bb8\u60a8\u5728\u9700\u8981\u65f6\u6dfb\u52a0\u6216\u79fb\u9664\u9879\u3002\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u8bed\u6cd5\u521b\u5efa\u6570\u7ec4\u5217\u8868\uff1a List&lt;int[]&gt; numbers = new ArrayList&lt;&gt;(); \u767b\u5f55\u540e\u590d\u5236 \u7136\u540e\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528 add() \u65b9\u6cd5\u5c06\u6570\u7ec4\u6dfb\u52a0\u5230\u5217\u8868\u4e2d\uff1a numbers.add(new int[]{1, 2, 3}); numbers.add(new int[]{4, 5, 6}); numbers.add(new int[]{7, 8, 9}); \u767b\u5f55\u540e\u590d\u5236 3. \u4f7f\u7528\u6d41\u5f0f\u5904\u7406 \u6d41\u5f0f\u5904\u7406\u63d0\u4f9b\u4e86\u4e00\u79cd\u7b80\u6d01\u7684\u65b9\u5f0f\u6765\u521b\u5efa\u548c\u64cd\u4f5c\u6570\u636e\u7ed3\u6784\u3002\u60a8\u53ef\u4ee5\u4f7f\u7528 [&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-38644","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/38644","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=38644"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/38644\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=38644"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=38644"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=38644"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}