{"id":64647,"date":"2025-05-03T13:14:47","date_gmt":"2025-05-03T05:14:47","guid":{"rendered":"https:\/\/fwq.ai\/blog\/64647\/"},"modified":"2025-05-03T13:14:47","modified_gmt":"2025-05-03T05:14:47","slug":"java%e9%87%8c%e6%80%8e%e4%b9%88%e5%ae%9a%e4%b9%89%e4%b8%80%e4%b8%aa%e6%95%b0%e7%bb%84-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/64647\/","title":{"rendered":"java\u91cc\u600e\u4e48\u5b9a\u4e49\u4e00\u4e2a\u6570\u7ec4"},"content":{"rendered":"<blockquote><p>\n  \u95ee\u9898\uff1a\u5728 java \u4e2d\u5982\u4f55\u5b9a\u4e49\u6570\u7ec4\uff1f\u7b54\u6848\uff1a\u4f7f\u7528\u6570\u636e\u7c7b\u578b[] \u6570\u7ec4\u540d = new \u6570\u636e\u7c7b\u578b[\u957f\u5ea6] \u8bed\u6cd5\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/04\/2024110405211852239.jpg\" class=\"aligncenter\" title=\"java\u91cc\u600e\u4e48\u5b9a\u4e49\u4e00\u4e2a\u6570\u7ec4\u63d2\u56fe\" alt=\"java\u91cc\u600e\u4e48\u5b9a\u4e49\u4e00\u4e2a\u6570\u7ec4\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5728 Java \u4e2d\u5b9a\u4e49\u6570\u7ec4<\/strong><\/p>\n<p>\u5728 Java \u4e2d\uff0c\u6570\u7ec4\u662f\u4e00\u79cd\u6570\u636e\u7ed3\u6784\uff0c\u7528\u4e8e\u5b58\u50a8\u76f8\u540c\u7c7b\u578b\u7684\u6570\u636e\u5143\u7d20\u96c6\u5408\u3002\u8981\u5b9a\u4e49\u4e00\u4e2a\u6570\u7ec4\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u8bed\u6cd5\uff1a<\/p>\n<pre>\u6570\u636e\u7c7b\u578b[] \u6570\u7ec4\u540d = new \u6570\u636e\u7c7b\u578b[\u957f\u5ea6];<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4f8b\u5982\uff0c\u8981\u5b9a\u4e49\u4e00\u4e2a\u5b58\u50a8 5 \u4e2a\u6574\u6570\u7684\u6570\u7ec4\uff0c\u8bed\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre>int[] myArray = new int[5];<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u6570\u7ec4\u7684\u5143\u7d20<\/strong><\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<p>\u6570\u7ec4\u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\u90fd\u5b58\u50a8\u5728\u7d22\u5f15\u4e3a 0 \u5230 length-1 \u7684\u4f4d\u7f6e\u3002\u53ef\u4ee5\u4f7f\u7528\u65b9\u62ec\u53f7\u8bbf\u95ee\u6570\u7ec4\u5143\u7d20\uff0c\u5176\u4e2d\u7d22\u5f15\u6307\u5b9a\u8981\u8bbf\u95ee\u7684\u5143\u7d20\u7684\u4f4d\u7f6e\u3002\u4f8b\u5982\uff1a<\/p>\n<pre>myArray[0] = 10; \/\/ \u5c06\u7b2c\u4e00\u4e2a\u5143\u7d20\u8bbe\u7f6e\u4e3a 10<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u6570\u7ec4\u7684\u957f\u5ea6<\/strong><\/p>\n<p>\u6570\u7ec4\u7684\u957f\u5ea6\u662f\u4e00\u6b21\u5b9a\u4e49\u7684\uff0c\u5e76\u4e14\u4e0d\u80fd\u5728\u4ee5\u540e\u66f4\u6539\u3002\u53ef\u4ee5\u4f7f\u7528 length \u5c5e\u6027\u8bbf\u95ee\u6570\u7ec4\u7684\u957f\u5ea6\u3002\u4f8b\u5982\uff1a<\/p>\n<pre>int length = myArray.length; \/\/ myArray \u7684\u957f\u5ea6<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u6ce8\u610f\uff1a<\/strong><\/p>\n<ul>\n<li>\u6570\u7ec4\u4e2d\u7684\u5143\u7d20\u9ed8\u8ba4\u521d\u59cb\u5316\u4e3a\u9ed8\u8ba4\u503c\uff08\u5bf9\u4e8e\u57fa\u672c\u7c7b\u578b\u4e3a 0\uff0c\u5bf9\u4e8e\u5f15\u7528\u7c7b\u578b\u4e3a null\uff09\u3002<\/li>\n<li>\u6570\u7ec4\u7684\u7d22\u5f15\u4ece 0 \u5f00\u59cb\uff0c\u56e0\u6b64\u7b2c\u4e00\u4e2a\u5143\u7d20\u7684\u7d22\u5f15\u4e3a 0\uff0c\u6700\u540e\u4e00\u4e2a\u5143\u7d20\u7684\u7d22\u5f15\u4e3a length-1\u3002<\/li>\n<li>\u6570\u7ec4\u662f\u4e00\u4e2a\u5bf9\u8c61\uff0c\u56e0\u6b64\u5b83\u53ef\u4ee5\u901a\u8fc7\u5f15\u7528\u4f20\u9012\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662fjava\u91cc\u600e\u4e48\u5b9a\u4e49\u4e00\u4e2a\u6570\u7ec4\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>\u95ee\u9898\uff1a\u5728 java \u4e2d\u5982\u4f55\u5b9a\u4e49\u6570\u7ec4\uff1f\u7b54\u6848\uff1a\u4f7f\u7528\u6570\u636e\u7c7b\u578b[] \u6570\u7ec4\u540d = new \u6570\u636e\u7c7b\u578b[\u957f\u5ea6] \u8bed\u6cd5\u3002 \u5728 Java \u4e2d\u5b9a\u4e49\u6570\u7ec4 \u5728 Java \u4e2d\uff0c\u6570\u7ec4\u662f\u4e00\u79cd\u6570\u636e\u7ed3\u6784\uff0c\u7528\u4e8e\u5b58\u50a8\u76f8\u540c\u7c7b\u578b\u7684\u6570\u636e\u5143\u7d20\u96c6\u5408\u3002\u8981\u5b9a\u4e49\u4e00\u4e2a\u6570\u7ec4\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u8bed\u6cd5\uff1a \u6570\u636e\u7c7b\u578b[] \u6570\u7ec4\u540d = new \u6570\u636e\u7c7b\u578b[\u957f\u5ea6]; \u767b\u5f55\u540e\u590d\u5236 \u4f8b\u5982\uff0c\u8981\u5b9a\u4e49\u4e00\u4e2a\u5b58\u50a8 5 \u4e2a\u6574\u6570\u7684\u6570\u7ec4\uff0c\u8bed\u6cd5\u5982\u4e0b\uff1a int[] myArray = new int[5]; \u767b\u5f55\u540e\u590d\u5236 \u6570\u7ec4\u7684\u5143\u7d20 \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b \u6570\u7ec4\u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\u90fd\u5b58\u50a8\u5728\u7d22\u5f15\u4e3a 0 \u5230 length-1 \u7684\u4f4d\u7f6e\u3002\u53ef\u4ee5\u4f7f\u7528\u65b9\u62ec\u53f7\u8bbf\u95ee\u6570\u7ec4\u5143\u7d20\uff0c\u5176\u4e2d\u7d22\u5f15\u6307\u5b9a\u8981\u8bbf\u95ee\u7684\u5143\u7d20\u7684\u4f4d\u7f6e\u3002\u4f8b\u5982\uff1a myArray[0] = 10; \/\/ \u5c06\u7b2c\u4e00\u4e2a\u5143\u7d20\u8bbe\u7f6e\u4e3a 10 \u767b\u5f55\u540e\u590d\u5236 \u6570\u7ec4\u7684\u957f\u5ea6 \u6570\u7ec4\u7684\u957f\u5ea6\u662f\u4e00\u6b21\u5b9a\u4e49\u7684\uff0c\u5e76\u4e14\u4e0d\u80fd\u5728\u4ee5\u540e\u66f4\u6539\u3002\u53ef\u4ee5\u4f7f\u7528 length \u5c5e\u6027\u8bbf\u95ee\u6570\u7ec4\u7684\u957f\u5ea6\u3002\u4f8b\u5982\uff1a int length = myArray.length; \/\/ myArray \u7684\u957f\u5ea6 \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-64647","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/64647","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=64647"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/64647\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=64647"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=64647"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=64647"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}