{"id":66661,"date":"2025-05-03T11:20:20","date_gmt":"2025-05-03T03:20:20","guid":{"rendered":"https:\/\/fwq.ai\/blog\/66661\/"},"modified":"2025-05-03T11:20:20","modified_gmt":"2025-05-03T03:20:20","slug":"java%e6%80%8e%e4%b9%88%e5%88%9b%e5%bb%ba%e6%95%b0%e7%bb%84%e5%ad%98%e5%ad%97%e7%ac%a6%e4%b8%b2-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/66661\/","title":{"rendered":"java\u600e\u4e48\u521b\u5efa\u6570\u7ec4\u5b58\u5b57\u7b26\u4e32"},"content":{"rendered":"<blockquote><p>\n  java \u4e2d\u521b\u5efa\u5b57\u7b26\u4e32\u6570\u7ec4\u6709\u4e09\u79cd\u65b9\u6cd5\uff1a\u4e00\u3001\u4f7f\u7528 string \u6570\u7ec4\u6765\u5b58\u50a8\u5bf9 string \u5bf9\u8c61\u7684\u5f15\u7528\uff1b\u4e8c\u3001\u4f7f\u7528 arraylist \u6765\u521b\u5efa\u53ef\u53d8\u957f\u5ea6\u6570\u7ec4\uff1b\u4e09\u3001\u4f7f\u7528\u521d\u59cb\u5316\u503c\u521d\u59cb\u5316\u5143\u7d20\u3002\u6570\u7ec4\u5143\u7d20\u53ef\u901a\u8fc7\u65b9\u62ec\u53f7\u8bbf\u95ee\uff0c\u800c arraylist \u5143\u7d20\u53ef\u901a\u8fc7 get() \u65b9\u6cd5\u8bbf\u95ee\u3002string \u6570\u7ec4\u65e0\u6cd5\u66f4\u6539\u5927\u5c0f\uff0c\u800c arraylist \u53ef\u4ee5\u4f7f\u7528 add() \u548c remove() \u65b9\u6cd5\u6dfb\u52a0\u548c\u5220\u9664\u5143\u7d20\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/16\/2024111612181853205.jpg\" class=\"aligncenter\" title=\"java\u600e\u4e48\u521b\u5efa\u6570\u7ec4\u5b58\u5b57\u7b26\u4e32\u63d2\u56fe\" alt=\"java\u600e\u4e48\u521b\u5efa\u6570\u7ec4\u5b58\u5b57\u7b26\u4e32\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5728 Java \u4e2d\u521b\u5efa\u6570\u7ec4\u5b58\u50a8\u5b57\u7b26\u4e32<\/strong><\/p>\n<p><strong>\u4e00\u3001\u4f7f\u7528 String[] \u6570\u7ec4<\/strong><\/p>\n<p>\u6700\u7b80\u5355\u7684\u65b9\u6cd5\u662f\u4f7f\u7528 String \u6570\u7ec4\u3002String \u6570\u7ec4\u662f\u4e00\u4e2a\u5f15\u7528\u6570\u7ec4\uff0c\u5b83\u5b58\u50a8\u5bf9 String \u5bf9\u8c61\u7684\u5f15\u7528\u3002<\/p>\n<pre>String[] names = new String[10];<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd9\u5c06\u521b\u5efa\u957f\u5ea6\u4e3a 10 \u7684 String \u6570\u7ec4\uff0c\u6570\u7ec4\u5143\u7d20\u7c7b\u578b\u4e3a String\u3002<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<p><strong>\u4e8c\u3001\u4f7f\u7528 ArrayList<\/strong><\/p>\n<p>\u5982\u679c\u60a8\u9700\u8981\u66f4\u7075\u6d3b\u7684\u6570\u7ec4\uff0c\u53ef\u4ee5\u4f7f\u7528 ArrayList\u3002ArrayList \u662f\u4e00\u4e2a\u53ef\u53d8\u957f\u5ea6\u6570\u7ec4\uff0c\u53ef\u4ee5\u81ea\u52a8\u589e\u52a0\u5927\u5c0f\u3002<\/p>\n<pre>ArrayList&lt;String&gt; names = new ArrayList&lt;&gt;();<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd9\u5c06\u521b\u5efa\u957f\u5ea6\u4e3a 0 \u7684 ArrayList\uff0c\u53ef\u4ee5\u6dfb\u52a0\u6216\u5220\u9664\u5143\u7d20\u3002<\/p>\n<p><strong>\u4e09\u3001\u521d\u59cb\u5316\u6570\u7ec4<\/strong><\/p>\n<p>\u5728\u521b\u5efa\u6570\u7ec4\u65f6\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u521d\u59cb\u5316\u503c\u521d\u59cb\u5316\u5143\u7d20\u3002<\/p>\n<pre>\/\/ \u4f7f\u7528 String[] \u6570\u7ec4\nString[] names = {\"John\", \"Mary\", \"Bob\"};\n\n\/\/ \u4f7f\u7528 ArrayList\nArrayList&lt;String&gt; names = new ArrayList&lt;&gt;(Arrays.asList(\"John\", \"Mary\", \"Bob\"));<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u56db\u3001\u8bbf\u95ee\u6570\u7ec4\u5143\u7d20<\/strong><\/p>\n<p>\u8981\u8bbf\u95ee\u6570\u7ec4\u5143\u7d20\uff0c\u53ef\u4ee5\u4f7f\u7528\u65b9\u62ec\u53f7\u3002<\/p>\n<ul>\n<li>String[] \u6570\u7ec4\uff1a names[i]<\/li>\n<li>ArrayList\uff1a names.get(i)<\/li>\n<\/ul>\n<p><strong>\u4e94\u3001\u6dfb\u52a0\u548c\u5220\u9664\u5143\u7d20<\/strong><\/p>\n<ul>\n<li>String[] \u6570\u7ec4\uff1a\u65e0\u6cd5\u66f4\u6539\u5927\u5c0f\uff0c\u5fc5\u987b\u4f7f\u7528\u53e6\u4e00\u4e2a\u6570\u7ec4\u3002<\/li>\n<li>ArrayList\uff1a\u53ef\u4ee5\u4f7f\u7528 add() \u548c remove() \u65b9\u6cd5\u6dfb\u52a0\u548c\u5220\u9664\u5143\u7d20\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662fjava\u600e\u4e48\u521b\u5efa\u6570\u7ec4\u5b58\u5b57\u7b26\u4e32\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 \u4e2d\u521b\u5efa\u5b57\u7b26\u4e32\u6570\u7ec4\u6709\u4e09\u79cd\u65b9\u6cd5\uff1a\u4e00\u3001\u4f7f\u7528 string \u6570\u7ec4\u6765\u5b58\u50a8\u5bf9 string \u5bf9\u8c61\u7684\u5f15\u7528\uff1b\u4e8c\u3001\u4f7f\u7528 arraylist \u6765\u521b\u5efa\u53ef\u53d8\u957f\u5ea6\u6570\u7ec4\uff1b\u4e09\u3001\u4f7f\u7528\u521d\u59cb\u5316\u503c\u521d\u59cb\u5316\u5143\u7d20\u3002\u6570\u7ec4\u5143\u7d20\u53ef\u901a\u8fc7\u65b9\u62ec\u53f7\u8bbf\u95ee\uff0c\u800c arraylist \u5143\u7d20\u53ef\u901a\u8fc7 get() \u65b9\u6cd5\u8bbf\u95ee\u3002string \u6570\u7ec4\u65e0\u6cd5\u66f4\u6539\u5927\u5c0f\uff0c\u800c arraylist \u53ef\u4ee5\u4f7f\u7528 add() \u548c remove() \u65b9\u6cd5\u6dfb\u52a0\u548c\u5220\u9664\u5143\u7d20\u3002 \u5728 Java \u4e2d\u521b\u5efa\u6570\u7ec4\u5b58\u50a8\u5b57\u7b26\u4e32 \u4e00\u3001\u4f7f\u7528 String[] \u6570\u7ec4 \u6700\u7b80\u5355\u7684\u65b9\u6cd5\u662f\u4f7f\u7528 String \u6570\u7ec4\u3002String \u6570\u7ec4\u662f\u4e00\u4e2a\u5f15\u7528\u6570\u7ec4\uff0c\u5b83\u5b58\u50a8\u5bf9 String \u5bf9\u8c61\u7684\u5f15\u7528\u3002 String[] names = new String[10]; \u767b\u5f55\u540e\u590d\u5236 \u8fd9\u5c06\u521b\u5efa\u957f\u5ea6\u4e3a 10 \u7684 String \u6570\u7ec4\uff0c\u6570\u7ec4\u5143\u7d20\u7c7b\u578b\u4e3a String\u3002 \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b \u4e8c\u3001\u4f7f\u7528 ArrayList \u5982\u679c\u60a8\u9700\u8981\u66f4\u7075\u6d3b\u7684\u6570\u7ec4\uff0c\u53ef\u4ee5\u4f7f\u7528 ArrayList\u3002ArrayList \u662f\u4e00\u4e2a\u53ef\u53d8\u957f\u5ea6\u6570\u7ec4\uff0c\u53ef\u4ee5\u81ea\u52a8\u589e\u52a0\u5927\u5c0f\u3002 ArrayList&lt;String&gt; names = new ArrayList&lt;&gt;(); \u767b\u5f55\u540e\u590d\u5236 [&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-66661","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/66661","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=66661"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/66661\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=66661"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=66661"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=66661"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}