{"id":39759,"date":"2024-11-26T08:36:29","date_gmt":"2024-11-26T00:36:29","guid":{"rendered":"https:\/\/fwq.ai\/blog\/39759\/"},"modified":"2024-11-26T08:36:29","modified_gmt":"2024-11-26T00:36:29","slug":"java%e4%ba%8c%e7%bb%b4%e6%95%b0%e7%bb%84%e7%9a%84%e9%95%bf%e5%ba%a6%e6%80%8e%e4%b9%88%e7%ae%97","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/39759\/","title":{"rendered":"java\u4e8c\u7ef4\u6570\u7ec4\u7684\u957f\u5ea6\u600e\u4e48\u7b97"},"content":{"rendered":"<blockquote><p>\n  java \u4e8c\u7ef4\u6570\u7ec4\u7684\u957f\u5ea6\u53ef\u4ee5\u901a\u8fc7\u5176 length \u5c5e\u6027\u83b7\u5f97\uff1a\u5916\u5c42\u6570\u7ec4\u7684\u957f\u5ea6\uff1a\u8fd4\u56de\u884c\u6570\u3002\u5185\u5c42\u6570\u7ec4\u7684\u957f\u5ea6\uff1a\u8fd4\u56de\u6bcf\u884c\u7684\u5217\u6570\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/17\/2024111709454338481.jpg\" class=\"aligncenter\" title=\"java\u4e8c\u7ef4\u6570\u7ec4\u7684\u957f\u5ea6\u600e\u4e48\u7b97\u63d2\u56fe\" alt=\"java\u4e8c\u7ef4\u6570\u7ec4\u7684\u957f\u5ea6\u600e\u4e48\u7b97\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u8ba1\u7b97 Java \u4e8c\u7ef4\u6570\u7ec4\u7684\u957f\u5ea6<\/strong><\/p>\n<p><strong>\u76f4\u63a5\u56de\u7b54\uff1a<\/strong><\/p>\n<p>Java \u4e8c\u7ef4\u6570\u7ec4\u7684\u957f\u5ea6\u53ef\u4ee5\u901a\u8fc7\u5176 length \u5c5e\u6027\u83b7\u5f97\u3002\u5b83\u8fd4\u56de\u5916\u5c42\u6570\u7ec4\u7684\u5143\u7d20\u6570\u91cf\uff0c\u4e5f\u5c31\u662f\u884c\u6570\u3002\u5185\u5c42\u6570\u7ec4\u7684\u957f\u5ea6\u53ef\u4ee5\u4f7f\u7528 length \u5c5e\u6027\u83b7\u53d6\uff0c\u5b83\u8fd4\u56de\u6bcf\u884c\u7684\u5143\u7d20\u6570\u91cf\uff0c\u4e5f\u5c31\u662f\u5217\u6570\u3002<\/p>\n<p><strong>\u8be6\u7ec6\u5c55\u5f00\uff1a<\/strong><\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<p><strong>\u5916\u5c42\u6570\u7ec4\u7684\u957f\u5ea6\uff1a<\/strong><\/p>\n<pre>int[][] array = new int[rows][columns];\nint rows = array.length; \/\/ \u8fd4\u56de\u5916\u5c42\u6570\u7ec4\u7684\u957f\u5ea6\uff08\u884c\u6570\uff09<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u5185\u5c42\u6570\u7ec4\u7684\u957f\u5ea6\uff1a<\/strong><\/p>\n<pre>for (int[] row : array) {\n    int columns = row.length; \/\/ \u8fd4\u56de\u5185\u5c42\u6570\u7ec4\u7684\u957f\u5ea6\uff08\u5217\u6570\uff09\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre>int[][] array = {\n    {1, 2, 3},\n    {4, 5, 6},\n    {7, 8, 9}\n};\n\nint rows = array.length; \/\/ 3\nint columns = array[0].length; \/\/ 3<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u6ce8\u610f\u4e8b\u9879\uff1a<\/strong><\/p>\n<ul>\n<li>\u5916\u5c42\u6570\u7ec4\u7684\u957f\u5ea6\u8868\u793a\u884c\u6570\uff0c\u800c\u5185\u5c42\u6570\u7ec4\u7684\u957f\u5ea6\u8868\u793a\u5217\u6570\u3002<\/li>\n<li>\u4e8c\u7ef4\u6570\u7ec4\u4e2d\u7684\u6bcf\u4e00\u884c\u90fd\u5fc5\u987b\u5177\u6709\u76f8\u540c\u7684\u5217\u6570\uff0c\u5426\u5219\u4f1a\u629b\u51fa ArrayIndexOutOfBoundsException\u3002<\/li>\n<li>\u4f7f\u7528 length \u5c5e\u6027\u662f\u4e00\u79cd\u83b7\u53d6 Java \u4e8c\u7ef4\u6570\u7ec4\u957f\u5ea6\u7684\u7b80\u4fbf\u65b9\u6cd5\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662fjava\u4e8c\u7ef4\u6570\u7ec4\u7684\u957f\u5ea6\u600e\u4e48\u7b97\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 \u4e8c\u7ef4\u6570\u7ec4\u7684\u957f\u5ea6\u53ef\u4ee5\u901a\u8fc7\u5176 length \u5c5e\u6027\u83b7\u5f97\uff1a\u5916\u5c42\u6570\u7ec4\u7684\u957f\u5ea6\uff1a\u8fd4\u56de\u884c\u6570\u3002\u5185\u5c42\u6570\u7ec4\u7684\u957f\u5ea6\uff1a\u8fd4\u56de\u6bcf\u884c\u7684\u5217\u6570\u3002 \u5982\u4f55\u8ba1\u7b97 Java \u4e8c\u7ef4\u6570\u7ec4\u7684\u957f\u5ea6 \u76f4\u63a5\u56de\u7b54\uff1a Java \u4e8c\u7ef4\u6570\u7ec4\u7684\u957f\u5ea6\u53ef\u4ee5\u901a\u8fc7\u5176 length \u5c5e\u6027\u83b7\u5f97\u3002\u5b83\u8fd4\u56de\u5916\u5c42\u6570\u7ec4\u7684\u5143\u7d20\u6570\u91cf\uff0c\u4e5f\u5c31\u662f\u884c\u6570\u3002\u5185\u5c42\u6570\u7ec4\u7684\u957f\u5ea6\u53ef\u4ee5\u4f7f\u7528 length \u5c5e\u6027\u83b7\u53d6\uff0c\u5b83\u8fd4\u56de\u6bcf\u884c\u7684\u5143\u7d20\u6570\u91cf\uff0c\u4e5f\u5c31\u662f\u5217\u6570\u3002 \u8be6\u7ec6\u5c55\u5f00\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b \u5916\u5c42\u6570\u7ec4\u7684\u957f\u5ea6\uff1a int[][] array = new int[rows][columns]; int rows = array.length; \/\/ \u8fd4\u56de\u5916\u5c42\u6570\u7ec4\u7684\u957f\u5ea6\uff08\u884c\u6570\uff09 \u767b\u5f55\u540e\u590d\u5236 \u5185\u5c42\u6570\u7ec4\u7684\u957f\u5ea6\uff1a for (int[] row : array) { int columns = row.length; \/\/ \u8fd4\u56de\u5185\u5c42\u6570\u7ec4\u7684\u957f\u5ea6\uff08\u5217\u6570\uff09 } \u767b\u5f55\u540e\u590d\u5236 \u793a\u4f8b\uff1a int[][] array = { {1, 2, 3}, {4, 5, 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-39759","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/39759","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=39759"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/39759\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=39759"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=39759"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=39759"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}