{"id":38600,"date":"2024-11-26T17:36:50","date_gmt":"2024-11-26T09:36:50","guid":{"rendered":"https:\/\/fwq.ai\/blog\/38600\/"},"modified":"2024-11-26T17:36:50","modified_gmt":"2024-11-26T09:36:50","slug":"java%e9%87%8c%e6%80%8e%e4%b9%88%e5%88%9b%e5%bb%ba%e4%ba%8c%e7%bb%b4%e6%95%b0%e7%bb%84","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/38600\/","title":{"rendered":"java\u91cc\u600e\u4e48\u521b\u5efa\u4e8c\u7ef4\u6570\u7ec4"},"content":{"rendered":"<blockquote><p>\n  \u5728 java \u4e2d\u521b\u5efa\u4e8c\u7ef4\u6570\u7ec4\u7684\u65b9\u6cd5\u6709\uff1a1. \u76f4\u63a5\u521b\u5efa\u548c\u521d\u59cb\u5316\uff1b2. \u4f7f\u7528 new \u5173\u952e\u5b57\u548c\u624b\u52a8\u8d4b\u503c\uff1b3. \u4f7f\u7528 arrays.fill() \u65b9\u6cd5\u586b\u5145\u6570\u7ec4\uff1b4. \u521b\u5efa\u5e26\u9ed8\u8ba4\u503c\u7684\u6570\u7ec4\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/15\/2024111503422899679.jpg\" class=\"aligncenter\" title=\"java\u91cc\u600e\u4e48\u521b\u5efa\u4e8c\u7ef4\u6570\u7ec4\u63d2\u56fe\" alt=\"java\u91cc\u600e\u4e48\u521b\u5efa\u4e8c\u7ef4\u6570\u7ec4\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u5728 Java \u4e2d\u521b\u5efa\u4e8c\u7ef4\u6570\u7ec4<\/strong><\/p>\n<p><strong>\u4e00\u3001\u76f4\u63a5\u521b\u5efa\u548c\u521d\u59cb\u5316<\/strong><\/p>\n<pre>int[][] myArray = {\n    {1, 2},\n    {3, 4},\n    {5, 6}\n};<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u4e8c\u3001\u4f7f\u7528 new \u5173\u952e\u5b57<\/strong><\/p>\n<pre>int[][] myArray = new int[3][2];\n\n\/\/ \u624b\u52a8\u8d4b\u503c\nmyArray[0][0] = 1;\nmyArray[0][1] = 2;\nmyArray[1][0] = 3;\nmyArray[1][1] = 4;\nmyArray[2][0] = 5;\nmyArray[2][1] = 6;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u4e09\u3001\u4f7f\u7528 Arrays.fill() \u65b9\u6cd5\u586b\u5145\u6570\u7ec4<\/strong><\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<pre>int[][] myArray = new int[3][2];\nArrays.fill(myArray, 0); \/\/ \u7528 0 \u586b\u5145\u6574\u4e2a\u6570\u7ec4<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u56db\u3001\u521b\u5efa\u5e26\u9ed8\u8ba4\u503c\u7684\u6570\u7ec4<\/strong><\/p>\n<pre>int[][] myArray = new int[3][2];\nint defaultValue = 10;\n\nfor (int i = 0; i &lt; myArray.length; i++) {\n    for (int j = 0; j &lt; myArray[i].length; j++) {\n        myArray[i][j] = defaultValue;\n    }\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fjava\u91cc\u600e\u4e48\u521b\u5efa\u4e8c\u7ef4\u6570\u7ec4\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>\u5728 java \u4e2d\u521b\u5efa\u4e8c\u7ef4\u6570\u7ec4\u7684\u65b9\u6cd5\u6709\uff1a1. \u76f4\u63a5\u521b\u5efa\u548c\u521d\u59cb\u5316\uff1b2. \u4f7f\u7528 new \u5173\u952e\u5b57\u548c\u624b\u52a8\u8d4b\u503c\uff1b3. \u4f7f\u7528 arrays.fill() \u65b9\u6cd5\u586b\u5145\u6570\u7ec4\uff1b4. \u521b\u5efa\u5e26\u9ed8\u8ba4\u503c\u7684\u6570\u7ec4\u3002 \u5982\u4f55\u5728 Java \u4e2d\u521b\u5efa\u4e8c\u7ef4\u6570\u7ec4 \u4e00\u3001\u76f4\u63a5\u521b\u5efa\u548c\u521d\u59cb\u5316 int[][] myArray = { {1, 2}, {3, 4}, {5, 6} }; \u767b\u5f55\u540e\u590d\u5236 \u4e8c\u3001\u4f7f\u7528 new \u5173\u952e\u5b57 int[][] myArray = new int[3][2]; \/\/ \u624b\u52a8\u8d4b\u503c myArray[0][0] = 1; myArray[0][1] = 2; myArray[1][0] = 3; myArray[1][1] = 4; myArray[2][0] = 5; myArray[2][1] = 6; [&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-38600","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/38600","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=38600"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/38600\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=38600"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=38600"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=38600"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}