{"id":37471,"date":"2024-11-26T14:49:28","date_gmt":"2024-11-26T06:49:28","guid":{"rendered":"https:\/\/fwq.ai\/blog\/37471\/"},"modified":"2024-11-26T14:49:28","modified_gmt":"2024-11-26T06:49:28","slug":"java%e9%9d%99%e6%80%81%e6%95%b0%e7%bb%84%e5%86%85%e5%ae%b9%e6%80%8e%e4%b9%88%e5%86%99","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/37471\/","title":{"rendered":"java\u9759\u6001\u6570\u7ec4\u5185\u5bb9\u600e\u4e48\u5199"},"content":{"rendered":"<blockquote><p>\n  \u9759\u6001\u6570\u7ec4\u662f\u7f16\u8bd1\u65f6\u5206\u914d\u56fa\u5b9a\u5927\u5c0f\u7684\u6570\u7ec4\uff0c\u65e0\u6cd5\u5728\u8fd0\u884c\u65f6\u66f4\u6539\u5927\u5c0f\u3002\u5176\u5185\u5bb9\u5305\u62ec\u5143\u7d20\u7c7b\u578b\u3001\u6570\u7ec4\u540d\u548c\u5b58\u50a8\u7684\u5143\u7d20\uff0c\u53ef\u901a\u8fc7\u7d22\u5f15\u8bbf\u95ee\u548c\u4fee\u6539\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/13\/2024111306063781635.jpg\" class=\"aligncenter\" title=\"java\u9759\u6001\u6570\u7ec4\u5185\u5bb9\u600e\u4e48\u5199\u63d2\u56fe\" alt=\"java\u9759\u6001\u6570\u7ec4\u5185\u5bb9\u600e\u4e48\u5199\u63d2\u56fe\" \/><\/p>\n<p><strong>Java \u9759\u6001\u6570\u7ec4\u7684\u5185\u5bb9<\/strong><\/p>\n<p><strong>\u4ec0\u4e48\u662f\u9759\u6001\u6570\u7ec4\uff1f<\/strong><\/p>\n<p>\u9759\u6001\u6570\u7ec4\u662f\u4e00\u79cd\u5728 Java \u4e2d\u58f0\u660e\u7684\u56fa\u5b9a\u5927\u5c0f\u6570\u7ec4\uff0c\u5176\u5143\u7d20\u5728\u7f16\u8bd1\u65f6\u5206\u914d\u3002\u4e0e\u52a8\u6001\u6570\u7ec4\uff08\u53c8\u79f0 ArrayList\uff09\u4e0d\u540c\uff0c\u5b83\u7684\u5927\u5c0f\u4e0d\u80fd\u5728\u8fd0\u884c\u65f6\u66f4\u6539\u3002<\/p>\n<p><strong>\u9759\u6001\u6570\u7ec4\u7684\u5185\u5bb9<\/strong><\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<p>\u9759\u6001\u6570\u7ec4\u7684\u5185\u5bb9\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u8bed\u6cd5\u5b9a\u4e49\uff1a<\/p>\n<pre>type[] arrayName = { element1, element2, ..., elementN };<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5176\u4e2d\uff1a<\/p>\n<ul>\n<li> <strong>type<\/strong> \u662f\u6570\u7ec4\u5143\u7d20\u7684\u6570\u636e\u7c7b\u578b\u3002<\/li>\n<li> <strong>arrayName<\/strong> \u662f\u6570\u7ec4\u7684\u540d\u79f0\u3002<\/li>\n<li> <strong>element1, &#8230; , elementN<\/strong> \u662f\u5b58\u50a8\u5728\u6570\u7ec4\u4e2d\u7684\u5143\u7d20\u3002<\/li>\n<\/ul>\n<p><strong>\u793a\u4f8b<\/strong><\/p>\n<pre>int[] numbers = { 1, 2, 3, 4, 5 };\nString[] names = { \"John\", \"Jane\", \"Bob\", \"Alice\" };<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u8bbf\u95ee\u548c\u4fee\u6539\u5143\u7d20<\/strong><\/p>\n<p>\u53ef\u4ee5\u4f7f\u7528\u6570\u7ec4\u5143\u7d20\u7684\u7d22\u5f15\u6765\u8bbf\u95ee\u548c\u4fee\u6539\u9759\u6001\u6570\u7ec4\u4e2d\u7684\u5143\u7d20\uff1a<\/p>\n<pre>\/\/ \u83b7\u53d6\u7b2c\u4e00\u4e2a\u5143\u7d20\nint firstNumber = numbers[0];\n\n\/\/ \u4fee\u6539\u6700\u540e\u4e00\u4e2a\u5143\u7d20\nnames[names.length - 1] = \"Tim\";<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u6ce8\u610f\u4e8b\u9879<\/strong><\/p>\n<ul>\n<li>\u6570\u7ec4\u5143\u7d20\u4e00\u65e6\u5206\u914d\uff0c\u5927\u5c0f\u5c31\u65e0\u6cd5\u66f4\u6539\u3002<\/li>\n<li>\u5c1d\u8bd5\u8bbf\u95ee\u8d85\u51fa\u6570\u7ec4\u8fb9\u754c\uff08\u4e0b\u6807\u8d85\u51fa\u8303\u56f4\uff09\u7684\u5143\u7d20\u4f1a\u5f15\u53d1 ArrayIndexOutOfBoundsException\u3002<\/li>\n<li>\u6570\u7ec4\u4e0d\u80fd\u5b58\u50a8 null \u503c\uff08\u9664\u4e86\u5f15\u7528\u7c7b\u578b\u6570\u7ec4\uff09\u3002<\/li>\n<li>\u6570\u7ec4\u662f\u5bf9\u8c61\uff0c\u56e0\u6b64\u53ef\u4ee5\u5c06\u5b83\u4eec\u4f5c\u4e3a\u53c2\u6570\u4f20\u9012\u7ed9\u65b9\u6cd5\uff0c\u5e76\u5c06\u5176\u8d4b\u503c\u7ed9\u5176\u4ed6\u6570\u7ec4\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662fjava\u9759\u6001\u6570\u7ec4\u5185\u5bb9\u600e\u4e48\u5199\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>\u9759\u6001\u6570\u7ec4\u662f\u7f16\u8bd1\u65f6\u5206\u914d\u56fa\u5b9a\u5927\u5c0f\u7684\u6570\u7ec4\uff0c\u65e0\u6cd5\u5728\u8fd0\u884c\u65f6\u66f4\u6539\u5927\u5c0f\u3002\u5176\u5185\u5bb9\u5305\u62ec\u5143\u7d20\u7c7b\u578b\u3001\u6570\u7ec4\u540d\u548c\u5b58\u50a8\u7684\u5143\u7d20\uff0c\u53ef\u901a\u8fc7\u7d22\u5f15\u8bbf\u95ee\u548c\u4fee\u6539\u3002 Java \u9759\u6001\u6570\u7ec4\u7684\u5185\u5bb9 \u4ec0\u4e48\u662f\u9759\u6001\u6570\u7ec4\uff1f \u9759\u6001\u6570\u7ec4\u662f\u4e00\u79cd\u5728 Java \u4e2d\u58f0\u660e\u7684\u56fa\u5b9a\u5927\u5c0f\u6570\u7ec4\uff0c\u5176\u5143\u7d20\u5728\u7f16\u8bd1\u65f6\u5206\u914d\u3002\u4e0e\u52a8\u6001\u6570\u7ec4\uff08\u53c8\u79f0 ArrayList\uff09\u4e0d\u540c\uff0c\u5b83\u7684\u5927\u5c0f\u4e0d\u80fd\u5728\u8fd0\u884c\u65f6\u66f4\u6539\u3002 \u9759\u6001\u6570\u7ec4\u7684\u5185\u5bb9 \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b \u9759\u6001\u6570\u7ec4\u7684\u5185\u5bb9\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u8bed\u6cd5\u5b9a\u4e49\uff1a type[] arrayName = { element1, element2, &#8230;, elementN }; \u767b\u5f55\u540e\u590d\u5236 \u5176\u4e2d\uff1a type \u662f\u6570\u7ec4\u5143\u7d20\u7684\u6570\u636e\u7c7b\u578b\u3002 arrayName \u662f\u6570\u7ec4\u7684\u540d\u79f0\u3002 element1, &#8230; , elementN \u662f\u5b58\u50a8\u5728\u6570\u7ec4\u4e2d\u7684\u5143\u7d20\u3002 \u793a\u4f8b int[] numbers = { 1, 2, 3, 4, 5 }; String[] names = { &#8220;John&#8221;, &#8220;Jane&#8221;, &#8220;Bob&#8221;, &#8220;Alice&#8221; }; \u767b\u5f55\u540e\u590d\u5236 \u8bbf\u95ee\u548c\u4fee\u6539\u5143\u7d20 \u53ef\u4ee5\u4f7f\u7528\u6570\u7ec4\u5143\u7d20\u7684\u7d22\u5f15\u6765\u8bbf\u95ee\u548c\u4fee\u6539\u9759\u6001\u6570\u7ec4\u4e2d\u7684\u5143\u7d20\uff1a \/\/ [&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-37471","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/37471","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=37471"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/37471\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=37471"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=37471"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=37471"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}