{"id":66211,"date":"2025-05-03T17:11:05","date_gmt":"2025-05-03T09:11:05","guid":{"rendered":"https:\/\/fwq.ai\/blog\/66211\/"},"modified":"2025-05-03T17:11:05","modified_gmt":"2025-05-03T09:11:05","slug":"java%e6%80%8e%e4%b9%88%e5%bc%95%e7%94%a8%e6%b3%9b%e5%9e%8b%e6%95%b0%e7%bb%84%e7%9a%84%e5%80%bc-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/66211\/","title":{"rendered":"java\u600e\u4e48\u5f15\u7528\u6cdb\u578b\u6570\u7ec4\u7684\u503c"},"content":{"rendered":"<blockquote><p>\n  \u5f15\u7528java\u6cdb\u578b\u6570\u7ec4\u7684\u503c\u4e0e\u5f15\u7528\u666e\u901a\u6570\u7ec4\u7c7b\u4f3c\uff0c\u6d89\u53ca\u4ee5\u4e0b\u6b65\u9aa4\uff1a\u521b\u5efa\u6cdb\u578b\u6570\u7ec4\uff1a\u6307\u5b9a\u6570\u7ec4\u5143\u7d20\u7c7b\u578b\u5e76\u8bbe\u7f6e\u5927\u5c0f\u3002\u5f15\u7528\u6570\u7ec4\u5143\u7d20\uff1a\u4f7f\u7528\u6570\u7ec4\u7d22\u5f15\u5f15\u7528\u5143\u7d20\uff0c\u4e0e\u666e\u901a\u6570\u7ec4\u76f8\u540c\u3002\u4fee\u6539\u6570\u7ec4\u5143\u7d20\uff1a\u901a\u8fc7\u6570\u7ec4\u7d22\u5f15\u4fee\u6539\u5143\u7d20\u3002\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u5fc5\u987b\u786e\u4fdd\u6570\u7ec4\u7d22\u5f15\u6709\u6548\uff0c\u5e76\u4e14\u6cdb\u578b\u6570\u7ec4\u7684\u6570\u636e\u7c7b\u578b\u5728\u521b\u5efa\u540e\u4e0d\u53ef\u66f4\u6539\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/15\/2024111503575948070.jpg\" class=\"aligncenter\" title=\"java\u600e\u4e48\u5f15\u7528\u6cdb\u578b\u6570\u7ec4\u7684\u503c\u63d2\u56fe\" alt=\"java\u600e\u4e48\u5f15\u7528\u6cdb\u578b\u6570\u7ec4\u7684\u503c\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u5f15\u7528 Java \u6cdb\u578b\u6570\u7ec4\u7684\u503c<\/strong><\/p>\n<p>\u5f15\u7528 Java \u6cdb\u578b\u6570\u7ec4\u4e2d\u7684\u503c\u4e0e\u5f15\u7528\u666e\u901a\u6570\u7ec4\u7c7b\u4f3c\uff0c\u4f46\u6709\u4e00\u4e9b\u989d\u5916\u7684\u8bed\u6cd5\u9700\u8981\u6ce8\u610f\u3002<\/p>\n<p><strong>\u521b\u5efa\u6cdb\u578b\u6570\u7ec4<\/strong><\/p>\n<p>\u9996\u5148\uff0c\u521b\u5efa\u6cdb\u578b\u6570\u7ec4\u65f6\uff0c\u9700\u8981\u6307\u5b9a\u6570\u7ec4\u5143\u7d20\u7684\u7c7b\u578b\uff1a<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<pre>T[] array = new T[size];<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5176\u4e2d T \u8868\u793a\u6570\u7ec4\u5143\u7d20\u7684\u6570\u636e\u7c7b\u578b\uff0csize \u8868\u793a\u6570\u7ec4\u7684\u5927\u5c0f\u3002<\/p>\n<p><strong>\u5f15\u7528\u6570\u7ec4\u5143\u7d20<\/strong><\/p>\n<p>\u5f15\u7528\u6cdb\u578b\u6570\u7ec4\u4e2d\u7684\u5143\u7d20\u9700\u8981\u4f7f\u7528\u6570\u7ec4\u7d22\u5f15\uff0c\u8bed\u6cd5\u4e0e\u666e\u901a\u6570\u7ec4\u76f8\u540c\uff1a<\/p>\n<pre>T value = array[index];<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5176\u4e2d index \u662f\u6570\u7ec4\u7d22\u5f15\uff0cvalue \u662f\u5f15\u7528\u5230\u7684\u6570\u7ec4\u5143\u7d20\u3002<\/p>\n<p><strong>\u4fee\u6539\u6570\u7ec4\u5143\u7d20<\/strong><\/p>\n<p>\u4e5f\u53ef\u4ee5\u901a\u8fc7\u6570\u7ec4\u7d22\u5f15\u4fee\u6539\u6cdb\u578b\u6570\u7ec4\u4e2d\u7684\u5143\u7d20\uff1a<\/p>\n<pre>array[index] = newValue;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5176\u4e2d newValue \u662f\u65b0\u7684\u6570\u7ec4\u5143\u7d20\u503c\u3002<\/p>\n<p><strong>\u4f8b\u5982<\/strong><\/p>\n<p>\u5047\u8bbe\u6709\u4e00\u4e2a\u540d\u4e3a String[] \u7684\u6cdb\u578b\u6570\u7ec4\uff1a<\/p>\n<pre>String[] names = new String[3];<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u53ef\u4ee5\u5f15\u7528\u6570\u7ec4\u4e2d\u7684\u7b2c\u4e00\u4e2a\u5143\u7d20\uff1a<\/p>\n<pre>String firstName = names[0]; \/\/ \u5f15\u7528\u7b2c\u4e00\u4e2a\u5143\u7d20<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5e76\u5c06\u5176\u4fee\u6539\u4e3a\u65b0\u503c\uff1a<\/p>\n<pre>names[0] = \"John\"; \/\/ \u4fee\u6539\u7b2c\u4e00\u4e2a\u5143\u7d20<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u6ce8\u610f\u4e8b\u9879<\/strong><\/p>\n<ul>\n<li>\u5728\u6cdb\u578b\u6570\u7ec4\u4e2d\u5f15\u7528\u5143\u7d20\u65f6\uff0c\u9700\u8981\u786e\u4fdd\u6570\u7ec4\u7d22\u5f15\u6709\u6548\u3002<\/li>\n<li>\u6cdb\u578b\u6570\u7ec4\u7684\u6570\u636e\u7c7b\u578b\u5728\u521b\u5efa\u540e\u4e0d\u80fd\u66f4\u6539\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662fjava\u600e\u4e48\u5f15\u7528\u6cdb\u578b\u6570\u7ec4\u7684\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>\u5f15\u7528java\u6cdb\u578b\u6570\u7ec4\u7684\u503c\u4e0e\u5f15\u7528\u666e\u901a\u6570\u7ec4\u7c7b\u4f3c\uff0c\u6d89\u53ca\u4ee5\u4e0b\u6b65\u9aa4\uff1a\u521b\u5efa\u6cdb\u578b\u6570\u7ec4\uff1a\u6307\u5b9a\u6570\u7ec4\u5143\u7d20\u7c7b\u578b\u5e76\u8bbe\u7f6e\u5927\u5c0f\u3002\u5f15\u7528\u6570\u7ec4\u5143\u7d20\uff1a\u4f7f\u7528\u6570\u7ec4\u7d22\u5f15\u5f15\u7528\u5143\u7d20\uff0c\u4e0e\u666e\u901a\u6570\u7ec4\u76f8\u540c\u3002\u4fee\u6539\u6570\u7ec4\u5143\u7d20\uff1a\u901a\u8fc7\u6570\u7ec4\u7d22\u5f15\u4fee\u6539\u5143\u7d20\u3002\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u5fc5\u987b\u786e\u4fdd\u6570\u7ec4\u7d22\u5f15\u6709\u6548\uff0c\u5e76\u4e14\u6cdb\u578b\u6570\u7ec4\u7684\u6570\u636e\u7c7b\u578b\u5728\u521b\u5efa\u540e\u4e0d\u53ef\u66f4\u6539\u3002 \u5982\u4f55\u5f15\u7528 Java \u6cdb\u578b\u6570\u7ec4\u7684\u503c \u5f15\u7528 Java \u6cdb\u578b\u6570\u7ec4\u4e2d\u7684\u503c\u4e0e\u5f15\u7528\u666e\u901a\u6570\u7ec4\u7c7b\u4f3c\uff0c\u4f46\u6709\u4e00\u4e9b\u989d\u5916\u7684\u8bed\u6cd5\u9700\u8981\u6ce8\u610f\u3002 \u521b\u5efa\u6cdb\u578b\u6570\u7ec4 \u9996\u5148\uff0c\u521b\u5efa\u6cdb\u578b\u6570\u7ec4\u65f6\uff0c\u9700\u8981\u6307\u5b9a\u6570\u7ec4\u5143\u7d20\u7684\u7c7b\u578b\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b T[] array = new T[size]; \u767b\u5f55\u540e\u590d\u5236 \u5176\u4e2d T \u8868\u793a\u6570\u7ec4\u5143\u7d20\u7684\u6570\u636e\u7c7b\u578b\uff0csize \u8868\u793a\u6570\u7ec4\u7684\u5927\u5c0f\u3002 \u5f15\u7528\u6570\u7ec4\u5143\u7d20 \u5f15\u7528\u6cdb\u578b\u6570\u7ec4\u4e2d\u7684\u5143\u7d20\u9700\u8981\u4f7f\u7528\u6570\u7ec4\u7d22\u5f15\uff0c\u8bed\u6cd5\u4e0e\u666e\u901a\u6570\u7ec4\u76f8\u540c\uff1a T value = array[index]; \u767b\u5f55\u540e\u590d\u5236 \u5176\u4e2d index \u662f\u6570\u7ec4\u7d22\u5f15\uff0cvalue \u662f\u5f15\u7528\u5230\u7684\u6570\u7ec4\u5143\u7d20\u3002 \u4fee\u6539\u6570\u7ec4\u5143\u7d20 \u4e5f\u53ef\u4ee5\u901a\u8fc7\u6570\u7ec4\u7d22\u5f15\u4fee\u6539\u6cdb\u578b\u6570\u7ec4\u4e2d\u7684\u5143\u7d20\uff1a array[index] = newValue; \u767b\u5f55\u540e\u590d\u5236 \u5176\u4e2d newValue \u662f\u65b0\u7684\u6570\u7ec4\u5143\u7d20\u503c\u3002 \u4f8b\u5982 \u5047\u8bbe\u6709\u4e00\u4e2a\u540d\u4e3a String[] \u7684\u6cdb\u578b\u6570\u7ec4\uff1a String[] names = new String[3]; \u767b\u5f55\u540e\u590d\u5236 \u53ef\u4ee5\u5f15\u7528\u6570\u7ec4\u4e2d\u7684\u7b2c\u4e00\u4e2a\u5143\u7d20\uff1a String firstName = names[0]; [&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-66211","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/66211","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=66211"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/66211\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=66211"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=66211"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=66211"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}