{"id":39914,"date":"2024-11-26T12:57:26","date_gmt":"2024-11-26T04:57:26","guid":{"rendered":"https:\/\/fwq.ai\/blog\/39914\/"},"modified":"2024-11-26T12:57:26","modified_gmt":"2024-11-26T04:57:26","slug":"java%e6%95%b0%e7%bb%84%e4%b8%ad%e5%8d%95%e4%b8%aa%e5%85%83%e7%b4%a0%e6%80%8e%e4%b9%88%e5%8f%96%e5%87%ba%e6%9d%a5","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/39914\/","title":{"rendered":"java\u6570\u7ec4\u4e2d\u5355\u4e2a\u5143\u7d20\u600e\u4e48\u53d6\u51fa\u6765"},"content":{"rendered":"<blockquote><p>\n  \u5982\u4f55\u4ece java \u6570\u7ec4\u4e2d\u83b7\u53d6\u5355\u4e2a\u5143\u7d20\uff1f\u4f7f\u7528 square brackets \u8bed\u6cd5 [index]\uff0c\u5176\u4e2d index \u662f\u5143\u7d20\u7684\u7d22\u5f15\uff08\u4ece 0 \u5f00\u59cb\uff09\u3002\u5bf9\u8c61\u6570\u7ec4\u9700\u8981\u8fdb\u884c\u7c7b\u578b\u8f6c\u6362\uff0c\u56e0\u4e3a\u5143\u7d20\u662f object \u7c7b\u578b\u7684\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/17\/2024111712481610548.jpg\" class=\"aligncenter\" title=\"java\u6570\u7ec4\u4e2d\u5355\u4e2a\u5143\u7d20\u600e\u4e48\u53d6\u51fa\u6765\u63d2\u56fe\" alt=\"java\u6570\u7ec4\u4e2d\u5355\u4e2a\u5143\u7d20\u600e\u4e48\u53d6\u51fa\u6765\u63d2\u56fe\" \/><\/p>\n<p><strong>Java \u6570\u7ec4\u4e2d\u83b7\u53d6\u5355\u4e2a\u5143\u7d20<\/strong><\/p>\n<p>Java \u6570\u7ec4\u662f\u4e00\u4e2a\u5bf9\u8c61\uff0c\u5176\u4e2d\u5305\u542b\u56fa\u5b9a\u957f\u5ea6\u7684\u5143\u7d20\u3002\u4e3a\u4e86\u4ece\u6570\u7ec4\u4e2d\u83b7\u53d6\u5355\u4e2a\u5143\u7d20\uff0c\u53ef\u4ee5\u4f7f\u7528\u65b9\u62ec\u53f7\u8bed\u6cd5\u6765\u6307\u5b9a\u7d22\u5f15\u3002<\/p>\n<p><strong>\u8bed\u6cd5\uff1a<\/strong><\/p>\n<pre>array[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>array \u662f\u6570\u7ec4\u53d8\u91cf\u540d\u3002<\/li>\n<li>index \u662f\u8981\u68c0\u7d22\u5143\u7d20\u7684\u7d22\u5f15\uff08\u4ece 0 \u5f00\u59cb\u8ba1\u6570\uff09\u3002<\/li>\n<\/ul>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre>int[] numbers = {1, 2, 3, 4, 5};\n\nint firstElement = numbers[0]; \/\/ \u53d6\u51fa\u7b2c\u4e00\u4e2a\u5143\u7d20\uff08\u503c\u4e3a 1\uff09\nint lastElement = numbers[numbers.length - 1]; \/\/ \u53d6\u51fa\u6700\u540e\u4e00\u4e2a\u5143\u7d20\uff08\u503c\u4e3a 5\uff09<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u6ce8\u610f\uff1a<\/strong><\/p>\n<ul>\n<li>\u6570\u7ec4\u7d22\u5f15\u5fc5\u987b\u662f\u975e\u8d1f\u6574\u6570\u3002<\/li>\n<li>\u5c1d\u8bd5\u8bbf\u95ee\u6570\u7ec4\u8d85\u8303\u56f4\u7684\u5143\u7d20\uff08\u5373\u7d22\u5f15\u5c0f\u4e8e 0 \u6216\u5927\u4e8e\u6216\u7b49\u4e8e\u6570\u7ec4\u957f\u5ea6\uff09\u5c06\u5bfc\u81f4\u6570\u7ec4\u4e0b\u6807\u8d8a\u754c\u5f02\u5e38 (ArrayIndexOutOfBoundsException)\u3002<\/li>\n<li>\u4e3a\u4e86\u9632\u6b62\u6570\u7ec4\u4e0b\u6807\u8d8a\u754c\uff0c\u53ef\u4ee5\u5728\u8bbf\u95ee\u5143\u7d20\u4e4b\u524d\u4f7f\u7528 Array.length \u5c5e\u6027\u6765\u68c0\u67e5\u6570\u7ec4\u957f\u5ea6\u3002<\/li>\n<\/ul>\n<p><strong>\u5bf9\u8c61\u6570\u7ec4\uff1a<\/strong><\/p>\n<p>\u5bf9\u4e8e\u5bf9\u8c61\u6570\u7ec4\uff0c\u83b7\u53d6\u5355\u4e2a\u5143\u7d20\u65f6\u5fc5\u987b\u8fdb\u884c\u7c7b\u578b\u8f6c\u6362\uff0c\u56e0\u4e3a\u6570\u7ec4\u5143\u7d20\u672c\u8eab\u662f Object \u7c7b\u578b\uff1a<\/p>\n<pre>Object[] objects = {\"hello\", \"world\", 3.14};\n\nString firstObject = (String) objects[0];<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fjava\u6570\u7ec4\u4e2d\u5355\u4e2a\u5143\u7d20\u600e\u4e48\u53d6\u51fa\u6765\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>\u5982\u4f55\u4ece java \u6570\u7ec4\u4e2d\u83b7\u53d6\u5355\u4e2a\u5143\u7d20\uff1f\u4f7f\u7528 square brackets \u8bed\u6cd5 [index]\uff0c\u5176\u4e2d index \u662f\u5143\u7d20\u7684\u7d22\u5f15\uff08\u4ece 0 \u5f00\u59cb\uff09\u3002\u5bf9\u8c61\u6570\u7ec4\u9700\u8981\u8fdb\u884c\u7c7b\u578b\u8f6c\u6362\uff0c\u56e0\u4e3a\u5143\u7d20\u662f object \u7c7b\u578b\u7684\u3002 Java \u6570\u7ec4\u4e2d\u83b7\u53d6\u5355\u4e2a\u5143\u7d20 Java \u6570\u7ec4\u662f\u4e00\u4e2a\u5bf9\u8c61\uff0c\u5176\u4e2d\u5305\u542b\u56fa\u5b9a\u957f\u5ea6\u7684\u5143\u7d20\u3002\u4e3a\u4e86\u4ece\u6570\u7ec4\u4e2d\u83b7\u53d6\u5355\u4e2a\u5143\u7d20\uff0c\u53ef\u4ee5\u4f7f\u7528\u65b9\u62ec\u53f7\u8bed\u6cd5\u6765\u6307\u5b9a\u7d22\u5f15\u3002 \u8bed\u6cd5\uff1a array[index] \u767b\u5f55\u540e\u590d\u5236 \u5176\u4e2d\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b array \u662f\u6570\u7ec4\u53d8\u91cf\u540d\u3002 index \u662f\u8981\u68c0\u7d22\u5143\u7d20\u7684\u7d22\u5f15\uff08\u4ece 0 \u5f00\u59cb\u8ba1\u6570\uff09\u3002 \u793a\u4f8b\uff1a int[] numbers = {1, 2, 3, 4, 5}; int firstElement = numbers[0]; \/\/ \u53d6\u51fa\u7b2c\u4e00\u4e2a\u5143\u7d20\uff08\u503c\u4e3a 1\uff09 int lastElement = numbers[numbers.length &#8211; 1]; \/\/ \u53d6\u51fa\u6700\u540e\u4e00\u4e2a\u5143\u7d20\uff08\u503c\u4e3a 5\uff09 \u767b\u5f55\u540e\u590d\u5236 \u6ce8\u610f\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-39914","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/39914","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=39914"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/39914\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=39914"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=39914"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=39914"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}