{"id":65806,"date":"2025-05-03T14:58:47","date_gmt":"2025-05-03T06:58:47","guid":{"rendered":"https:\/\/fwq.ai\/blog\/65806\/"},"modified":"2025-05-03T14:58:47","modified_gmt":"2025-05-03T06:58:47","slug":"java%e6%95%b0%e7%bb%84-%e5%8f%98%e9%87%8f%e6%80%8e%e4%b9%88%e5%ad%98%e5%80%bc-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/65806\/","title":{"rendered":"java\u6570\u7ec4 \u53d8\u91cf\u600e\u4e48\u5b58\u503c"},"content":{"rendered":"<blockquote><p>\n  java \u6570\u7ec4\u53d8\u91cf\u901a\u8fc7\u7d22\u5f15\u8bbf\u95ee\u5143\u7d20\u8fdb\u884c\u8d4b\u503c\u5b58\u50a8\u503c\u3002\u6b65\u9aa4\uff1a\u58f0\u660e\u6570\u7ec4\u53d8\u91cf\uff1adatatype[] arrayname;\u5206\u914d\u5185\u5b58\uff1aarrayname = new datatype[length];\u5b58\u50a8\u503c\uff1aarrayname[index] = value;\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/13\/2024111311034817330.jpg\" class=\"aligncenter\" title=\"java\u6570\u7ec4 \u53d8\u91cf\u600e\u4e48\u5b58\u503c\u63d2\u56fe\" alt=\"java\u6570\u7ec4 \u53d8\u91cf\u600e\u4e48\u5b58\u503c\u63d2\u56fe\" \/><\/p>\n<h2>Java \u6570\u7ec4\u53d8\u91cf\u5b58\u50a8\u503c\u7684\u65b9\u6cd5<\/h2>\n<p>Java \u4e2d\u6570\u7ec4\u53d8\u91cf\u5b58\u50a8\u503c\u7684\u65b9\u6cd5\u662f\u901a\u8fc7\u7d22\u5f15\u8bbf\u95ee\u6570\u7ec4\u5143\u7d20\u5e76\u5bf9\u5176\u8fdb\u884c\u8d4b\u503c\u3002\u6570\u7ec4\u7d22\u5f15\u4ece 0 \u5f00\u59cb\uff0c\u6bcf\u4e2a\u5143\u7d20\u7684\u7d22\u5f15\u8868\u793a\u5b83\u5728\u6570\u7ec4\u4e2d\u7684\u4f4d\u7f6e\u3002<\/p>\n<h3>\u5b58\u50a8\u503c\u6b65\u9aa4<\/h3>\n<ol>\n<li> <strong>\u58f0\u660e\u6570\u7ec4\u53d8\u91cf\uff1a<\/strong>\u4f7f\u7528 datatype[] arrayName; \u58f0\u660e\u4e00\u4e2a\u6570\u7ec4\u53d8\u91cf\uff0c\u5176\u4e2d datatype \u662f\u6570\u7ec4\u4e2d\u5143\u7d20\u7684\u6570\u636e\u7c7b\u578b\uff0carrayName \u662f\u6570\u7ec4\u7684\u540d\u79f0\u3002<\/li>\n<li> <strong>\u5206\u914d\u5185\u5b58\uff1a<\/strong>\u4f7f\u7528 new \u5173\u952e\u5b57\u4e3a\u6570\u7ec4\u5206\u914d\u5185\u5b58\u5e76\u6307\u5b9a\u5176\u957f\u5ea6\u3002 \u4f8b\u5982\uff1aarrayName = new datatype[length];<\/li>\n<li> <strong>\u5b58\u50a8\u503c\uff1a<\/strong>\u4f7f\u7528\u65b9\u62ec\u53f7 [] \u8bbf\u95ee\u6570\u7ec4\u5143\u7d20\u5e76\u5bf9\u5b83\u4eec\u8fdb\u884c\u8d4b\u503c\u3002 \u4f8b\u5982\uff1aarrayName[index] = value;<\/li>\n<\/ol>\n<h3>\u4ee3\u7801\u793a\u4f8b<\/h3>\n<p>\u4ee5\u4e0b\u4ee3\u7801\u521b\u5efa\u4e00\u4e2a\u6574\u578b\u6570\u7ec4\u5e76\u5b58\u50a8\u4e24\u4e2a\u503c\uff1a<\/p>\n<pre>int[] myArray = new int[2];\nmyArray[0] = 10;\nmyArray[1] = 20;<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u5b58\u50a8\u503c\u540e\uff0c\u53ef\u4ee5\u901a\u8fc7\u7d22\u5f15\u8bbf\u95ee\u5e76\u4fee\u6539\u6570\u7ec4\u4e2d\u7684\u5143\u7d20\u3002<\/p>\n<h3>\u6ce8\u610f\u4e8b\u9879<\/h3>\n<ul>\n<li>\u6570\u7ec4\u957f\u5ea6\u5728\u521b\u5efa\u540e\u4e0d\u80fd\u6539\u53d8\u3002<\/li>\n<li>\u8bbf\u95ee\u6570\u7ec4\u5143\u7d20\u65f6\uff0c\u7d22\u5f15\u5fc5\u987b\u5728 0 \u548c arrayName.length &#8211; 1 \u4e4b\u95f4\u3002<\/li>\n<li>\u8bbf\u95ee\u4e0d\u5c5e\u4e8e\u6570\u7ec4\u7684\u7d22\u5f15\u53ef\u80fd\u4f1a\u5bfc\u81f4\u6570\u7ec4\u4e0b\u6807\u8d8a\u754c\u5f02\u5e38 (ArrayIndexOutOfBoundsException)\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662fjava\u6570\u7ec4 \u53d8\u91cf\u600e\u4e48\u5b58\u503c\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>java \u6570\u7ec4\u53d8\u91cf\u901a\u8fc7\u7d22\u5f15\u8bbf\u95ee\u5143\u7d20\u8fdb\u884c\u8d4b\u503c\u5b58\u50a8\u503c\u3002\u6b65\u9aa4\uff1a\u58f0\u660e\u6570\u7ec4\u53d8\u91cf\uff1adatatype[] arrayname;\u5206\u914d\u5185\u5b58\uff1aarrayname = new datatype[length];\u5b58\u50a8\u503c\uff1aarrayname[index] = value; Java \u6570\u7ec4\u53d8\u91cf\u5b58\u50a8\u503c\u7684\u65b9\u6cd5 Java \u4e2d\u6570\u7ec4\u53d8\u91cf\u5b58\u50a8\u503c\u7684\u65b9\u6cd5\u662f\u901a\u8fc7\u7d22\u5f15\u8bbf\u95ee\u6570\u7ec4\u5143\u7d20\u5e76\u5bf9\u5176\u8fdb\u884c\u8d4b\u503c\u3002\u6570\u7ec4\u7d22\u5f15\u4ece 0 \u5f00\u59cb\uff0c\u6bcf\u4e2a\u5143\u7d20\u7684\u7d22\u5f15\u8868\u793a\u5b83\u5728\u6570\u7ec4\u4e2d\u7684\u4f4d\u7f6e\u3002 \u5b58\u50a8\u503c\u6b65\u9aa4 \u58f0\u660e\u6570\u7ec4\u53d8\u91cf\uff1a\u4f7f\u7528 datatype[] arrayName; \u58f0\u660e\u4e00\u4e2a\u6570\u7ec4\u53d8\u91cf\uff0c\u5176\u4e2d datatype \u662f\u6570\u7ec4\u4e2d\u5143\u7d20\u7684\u6570\u636e\u7c7b\u578b\uff0carrayName \u662f\u6570\u7ec4\u7684\u540d\u79f0\u3002 \u5206\u914d\u5185\u5b58\uff1a\u4f7f\u7528 new \u5173\u952e\u5b57\u4e3a\u6570\u7ec4\u5206\u914d\u5185\u5b58\u5e76\u6307\u5b9a\u5176\u957f\u5ea6\u3002 \u4f8b\u5982\uff1aarrayName = new datatype[length]; \u5b58\u50a8\u503c\uff1a\u4f7f\u7528\u65b9\u62ec\u53f7 [] \u8bbf\u95ee\u6570\u7ec4\u5143\u7d20\u5e76\u5bf9\u5b83\u4eec\u8fdb\u884c\u8d4b\u503c\u3002 \u4f8b\u5982\uff1aarrayName[index] = value; \u4ee3\u7801\u793a\u4f8b \u4ee5\u4e0b\u4ee3\u7801\u521b\u5efa\u4e00\u4e2a\u6574\u578b\u6570\u7ec4\u5e76\u5b58\u50a8\u4e24\u4e2a\u503c\uff1a int[] myArray = new int[2]; myArray[0] = 10; myArray[1] = 20; \u767b\u5f55\u540e\u590d\u5236 \u5b58\u50a8\u503c\u540e\uff0c\u53ef\u4ee5\u901a\u8fc7\u7d22\u5f15\u8bbf\u95ee\u5e76\u4fee\u6539\u6570\u7ec4\u4e2d\u7684\u5143\u7d20\u3002 \u6ce8\u610f\u4e8b\u9879 \u6570\u7ec4\u957f\u5ea6\u5728\u521b\u5efa\u540e\u4e0d\u80fd\u6539\u53d8\u3002 \u8bbf\u95ee\u6570\u7ec4\u5143\u7d20\u65f6\uff0c\u7d22\u5f15\u5fc5\u987b\u5728 0 \u548c [&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-65806","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/65806","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=65806"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/65806\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=65806"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=65806"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=65806"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}