{"id":38546,"date":"2024-11-26T09:05:43","date_gmt":"2024-11-26T01:05:43","guid":{"rendered":"https:\/\/fwq.ai\/blog\/38546\/"},"modified":"2024-11-26T09:05:43","modified_gmt":"2024-11-26T01:05:43","slug":"java-%e6%80%8e%e4%b9%88%e5%ae%9a%e4%b9%89%e7%bb%93%e6%9e%84%e4%bd%93%e6%95%b0%e7%bb%84%e7%9a%84%e9%95%bf%e5%ba%a6","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/38546\/","title":{"rendered":"java \u600e\u4e48\u5b9a\u4e49\u7ed3\u6784\u4f53\u6570\u7ec4\u7684\u957f\u5ea6"},"content":{"rendered":"<blockquote><p>\n  java \u4e2d\u5b9a\u4e49\u7ed3\u6784\u4f53\u6570\u7ec4\u7684\u957f\u5ea6\u9700\u8981\u4ee5\u4e0b\u6b65\u9aa4\uff1a\u5b9a\u4e49\u7ed3\u6784\u4f53\u672c\u8eab\u3002\u4f7f\u7528\u4ee5\u4e0b\u8bed\u6cd5\u6307\u5b9a\u6570\u7ec4\u957f\u5ea6\uff1astructname[] arrayname = new structname[numberofelements]\u3002\u8bbf\u95ee\u6570\u7ec4\u5143\u7d20\uff1aarrayname[index]\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/15\/2024111503034679855.jpg\" class=\"aligncenter\" title=\"java \u600e\u4e48\u5b9a\u4e49\u7ed3\u6784\u4f53\u6570\u7ec4\u7684\u957f\u5ea6\u63d2\u56fe\" alt=\"java \u600e\u4e48\u5b9a\u4e49\u7ed3\u6784\u4f53\u6570\u7ec4\u7684\u957f\u5ea6\u63d2\u56fe\" \/><\/p>\n<p><strong>Java \u4e2d\u5b9a\u4e49\u7ed3\u6784\u4f53\u6570\u7ec4\u7684\u957f\u5ea6<\/strong><\/p>\n<p>\u5728 Java \u4e2d\uff0c\u7ed3\u6784\u4f53\uff08\u53c8\u79f0\u6570\u636e\u7ed3\u6784\uff09\u662f\u4e00\u4e2a\u5305\u542b\u4e00\u7ec4\u76f8\u5173\u6570\u636e\u7684\u590d\u5408\u6570\u636e\u7c7b\u578b\u3002\u8981\u5b9a\u4e49\u4e00\u4e2a\u7ed3\u6784\u4f53\u6570\u7ec4\uff0c\u5fc5\u987b\u9996\u5148\u5b9a\u4e49\u7ed3\u6784\u4f53\u672c\u8eab\uff0c\u7136\u540e\u6307\u5b9a\u6570\u7ec4\u4e2d\u5143\u7d20\u7684\u4e2a\u6570\u3002<\/p>\n<p><strong>\u5b9a\u4e49\u7ed3\u6784\u4f53\u6570\u7ec4\u7684\u957f\u5ea6\uff1a<\/strong><\/p>\n<pre>structName[] arrayName = new structName[numberOfElements];<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5176\u4e2d\uff1a<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<ul>\n<li>structName \u662f\u7ed3\u6784\u4f53\u540d\u79f0\u3002<\/li>\n<li>arrayName \u662f\u6570\u7ec4\u540d\u79f0\u3002<\/li>\n<li>numberOfElements \u662f\u6570\u7ec4\u4e2d\u5143\u7d20\u7684\u6570\u91cf\u3002<\/li>\n<\/ul>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<p>\u5047\u8bbe\u6709\u4e00\u4e2a\u540d\u4e3a Employee \u7684\u7ed3\u6784\u4f53\uff0c\u5305\u542b name \u548c salary \u4e24\u4e2a\u6210\u5458\u53d8\u91cf\u3002\u8981\u5b9a\u4e49\u4e00\u4e2a\u5305\u542b 5 \u4e2a Employee \u7ed3\u6784\u4f53\u7684\u6570\u7ec4\uff0c\u9700\u8981\u8fd9\u6837\u505a\uff1a<\/p>\n<pre>Employee[] employees = new Employee[5];<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u73b0\u5728\uff0cemployees \u6570\u7ec4\u5305\u542b 5 \u4e2a Employee \u7ed3\u6784\u4f53\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u7d22\u5f15\u8bbf\u95ee\u6bcf\u4e2a\u5143\u7d20\uff1a<\/p>\n<pre>employees[0].name = \"John Doe\";\nemployees[1].salary = 100000;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u8bbf\u95ee\u6570\u7ec4\u5143\u7d20\uff1a<\/strong><\/p>\n<p>\u8981\u8bbf\u95ee\u6570\u7ec4\u4e2d\u7684\u5355\u4e2a\u5143\u7d20\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u8bed\u6cd5\uff1a<\/p>\n<pre>arrayName[index]<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5176\u4e2d\uff1a<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<ul>\n<li>arrayName \u662f\u6570\u7ec4\u540d\u79f0\u3002<\/li>\n<li>index \u662f\u5143\u7d20\u7d22\u5f15\uff0c\u4ece 0 \u5f00\u59cb\u3002<\/li>\n<\/ul>\n<p><strong>\u6ce8\u610f\uff1a<\/strong><\/p>\n<ul>\n<li>\u7ed3\u6784\u4f53\u6570\u7ec4\u4e2d\u5143\u7d20\u7684\u6570\u91cf\u5fc5\u987b\u5728\u5b9a\u4e49\u6570\u7ec4\u65f6\u6307\u5b9a\u3002<\/li>\n<li>\u4e00\u65e6\u5b9a\u4e49\u4e86\u6570\u7ec4\u5927\u5c0f\uff0c\u5c31\u4e0d\u80fd\u66f4\u6539\u3002<\/li>\n<li>\u5982\u679c\u5c1d\u8bd5\u8bbf\u95ee\u8d85\u51fa\u6570\u7ec4\u754c\u9650\u7684\u5143\u7d20\uff0c\u5c06\u4f1a\u629b\u51fa ArrayIndexOutOfBoundsException \u5f02\u5e38\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662fjava \u600e\u4e48\u5b9a\u4e49\u7ed3\u6784\u4f53\u6570\u7ec4\u7684\u957f\u5ea6\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\u5b9a\u4e49\u7ed3\u6784\u4f53\u6570\u7ec4\u7684\u957f\u5ea6\u9700\u8981\u4ee5\u4e0b\u6b65\u9aa4\uff1a\u5b9a\u4e49\u7ed3\u6784\u4f53\u672c\u8eab\u3002\u4f7f\u7528\u4ee5\u4e0b\u8bed\u6cd5\u6307\u5b9a\u6570\u7ec4\u957f\u5ea6\uff1astructname[] arrayname = new structname[numberofelements]\u3002\u8bbf\u95ee\u6570\u7ec4\u5143\u7d20\uff1aarrayname[index]\u3002 Java \u4e2d\u5b9a\u4e49\u7ed3\u6784\u4f53\u6570\u7ec4\u7684\u957f\u5ea6 \u5728 Java \u4e2d\uff0c\u7ed3\u6784\u4f53\uff08\u53c8\u79f0\u6570\u636e\u7ed3\u6784\uff09\u662f\u4e00\u4e2a\u5305\u542b\u4e00\u7ec4\u76f8\u5173\u6570\u636e\u7684\u590d\u5408\u6570\u636e\u7c7b\u578b\u3002\u8981\u5b9a\u4e49\u4e00\u4e2a\u7ed3\u6784\u4f53\u6570\u7ec4\uff0c\u5fc5\u987b\u9996\u5148\u5b9a\u4e49\u7ed3\u6784\u4f53\u672c\u8eab\uff0c\u7136\u540e\u6307\u5b9a\u6570\u7ec4\u4e2d\u5143\u7d20\u7684\u4e2a\u6570\u3002 \u5b9a\u4e49\u7ed3\u6784\u4f53\u6570\u7ec4\u7684\u957f\u5ea6\uff1a structName[] arrayName = new structName[numberOfElements]; \u767b\u5f55\u540e\u590d\u5236 \u5176\u4e2d\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b structName \u662f\u7ed3\u6784\u4f53\u540d\u79f0\u3002 arrayName \u662f\u6570\u7ec4\u540d\u79f0\u3002 numberOfElements \u662f\u6570\u7ec4\u4e2d\u5143\u7d20\u7684\u6570\u91cf\u3002 \u793a\u4f8b\uff1a \u5047\u8bbe\u6709\u4e00\u4e2a\u540d\u4e3a Employee \u7684\u7ed3\u6784\u4f53\uff0c\u5305\u542b name \u548c salary \u4e24\u4e2a\u6210\u5458\u53d8\u91cf\u3002\u8981\u5b9a\u4e49\u4e00\u4e2a\u5305\u542b 5 \u4e2a Employee \u7ed3\u6784\u4f53\u7684\u6570\u7ec4\uff0c\u9700\u8981\u8fd9\u6837\u505a\uff1a Employee[] employees = new Employee[5]; \u767b\u5f55\u540e\u590d\u5236 \u73b0\u5728\uff0cemployees \u6570\u7ec4\u5305\u542b 5 \u4e2a Employee \u7ed3\u6784\u4f53\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u7d22\u5f15\u8bbf\u95ee\u6bcf\u4e2a\u5143\u7d20\uff1a employees[0].name = &#8220;John Doe&#8221;; employees[1].salary [&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-38546","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/38546","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=38546"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/38546\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=38546"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=38546"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=38546"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}