{"id":65558,"date":"2025-05-03T16:46:50","date_gmt":"2025-05-03T08:46:50","guid":{"rendered":"https:\/\/fwq.ai\/blog\/65558\/"},"modified":"2025-05-03T16:46:50","modified_gmt":"2025-05-03T08:46:50","slug":"java-%e6%95%b0%e7%bb%84%e7%9a%84%e9%95%bf%e5%ba%a6%e6%80%8e%e4%b9%88%e5%a2%9e%e5%8a%a0-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/65558\/","title":{"rendered":"java \u6570\u7ec4\u7684\u957f\u5ea6\u600e\u4e48\u589e\u52a0"},"content":{"rendered":"<blockquote><p>\n  java \u6570\u7ec4\u7684\u957f\u5ea6\u4e0d\u53ef\u76f4\u63a5\u66f4\u6539\uff0c\u4f46\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u65b9\u6cd5\u95f4\u63a5\u589e\u52a0\uff1a\u521b\u5efa\u65b0\u6570\u7ec4\u5e76\u590d\u5236\u65e7\u6570\u7ec4\u5143\u7d20\uff1b\u4f7f\u7528\u53ef\u81ea\u52a8\u8c03\u6574\u5927\u5c0f\u7684 arraylist \u5e76\u8f6c\u6362\u6570\u7ec4\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/13\/2024111303481592415.jpg\" class=\"aligncenter\" title=\"java \u6570\u7ec4\u7684\u957f\u5ea6\u600e\u4e48\u589e\u52a0\u63d2\u56fe\" alt=\"java \u6570\u7ec4\u7684\u957f\u5ea6\u600e\u4e48\u589e\u52a0\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u589e\u52a0 Java \u6570\u7ec4\u7684\u957f\u5ea6<\/strong><\/p>\n<p>Java \u6570\u7ec4\u5728\u521b\u5efa\u540e\u65e0\u6cd5\u76f4\u63a5\u6539\u53d8\u957f\u5ea6\u3002\u7136\u800c\uff0c\u6709\u4e24\u79cd\u65b9\u6cd5\u53ef\u4ee5\u95f4\u63a5\u589e\u52a0\u6570\u7ec4\u7684\u957f\u5ea6\uff1a<\/p>\n<p><strong>1. \u590d\u5236\u5230\u65b0\u6570\u7ec4<\/strong><\/p>\n<p>\u521b\u5efa\u5305\u542b\u6240\u9700\u65b0\u957f\u5ea6\u7684\u65b0\u6570\u7ec4\uff0c\u7136\u540e\u5c06\u65e7\u6570\u7ec4\u4e2d\u7684\u5143\u7d20\u590d\u5236\u5230\u65b0\u6570\u7ec4\u4e2d\u3002\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<pre>int[] oldArray = {1, 2, 3};\nint[] newArray = new int[oldArray.length + 5];\n\nSystem.arraycopy(oldArray, 0, newArray, 0, oldArray.length);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>2. \u4f7f\u7528 ArrayList<\/strong><\/p>\n<p>ArrayList \u662f\u52a8\u6001\u6570\u7ec4\uff0c\u53ef\u4ee5\u6839\u636e\u9700\u8981\u81ea\u52a8\u8c03\u6574\u5927\u5c0f\u3002\u8981\u5c06\u6570\u7ec4\u8f6c\u6362\u4e3a ArrayList\uff0c\u7136\u540e\u5728\u9700\u8981\u65f6\u6dfb\u52a0\u5143\u7d20\u5373\u53ef\u3002\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<pre>int[] oldArray = {1, 2, 3};\nArrayList&lt;Integer&gt; arrayList = new ArrayList&lt;&gt;(Arrays.asList(oldArray));\n\narrayList.add(4);\narrayList.add(5);\n\nint[] newArray = arrayList.stream().mapToInt(Integer::intValue).toArray();<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fjava \u6570\u7ec4\u7684\u957f\u5ea6\u600e\u4e48\u589e\u52a0\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\u7684\u957f\u5ea6\u4e0d\u53ef\u76f4\u63a5\u66f4\u6539\uff0c\u4f46\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u65b9\u6cd5\u95f4\u63a5\u589e\u52a0\uff1a\u521b\u5efa\u65b0\u6570\u7ec4\u5e76\u590d\u5236\u65e7\u6570\u7ec4\u5143\u7d20\uff1b\u4f7f\u7528\u53ef\u81ea\u52a8\u8c03\u6574\u5927\u5c0f\u7684 arraylist \u5e76\u8f6c\u6362\u6570\u7ec4\u3002 \u5982\u4f55\u589e\u52a0 Java \u6570\u7ec4\u7684\u957f\u5ea6 Java \u6570\u7ec4\u5728\u521b\u5efa\u540e\u65e0\u6cd5\u76f4\u63a5\u6539\u53d8\u957f\u5ea6\u3002\u7136\u800c\uff0c\u6709\u4e24\u79cd\u65b9\u6cd5\u53ef\u4ee5\u95f4\u63a5\u589e\u52a0\u6570\u7ec4\u7684\u957f\u5ea6\uff1a 1. \u590d\u5236\u5230\u65b0\u6570\u7ec4 \u521b\u5efa\u5305\u542b\u6240\u9700\u65b0\u957f\u5ea6\u7684\u65b0\u6570\u7ec4\uff0c\u7136\u540e\u5c06\u65e7\u6570\u7ec4\u4e2d\u7684\u5143\u7d20\u590d\u5236\u5230\u65b0\u6570\u7ec4\u4e2d\u3002\u793a\u4f8b\u4ee3\u7801\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b int[] oldArray = {1, 2, 3}; int[] newArray = new int[oldArray.length + 5]; System.arraycopy(oldArray, 0, newArray, 0, oldArray.length); \u767b\u5f55\u540e\u590d\u5236 2. \u4f7f\u7528 ArrayList ArrayList \u662f\u52a8\u6001\u6570\u7ec4\uff0c\u53ef\u4ee5\u6839\u636e\u9700\u8981\u81ea\u52a8\u8c03\u6574\u5927\u5c0f\u3002\u8981\u5c06\u6570\u7ec4\u8f6c\u6362\u4e3a ArrayList\uff0c\u7136\u540e\u5728\u9700\u8981\u65f6\u6dfb\u52a0\u5143\u7d20\u5373\u53ef\u3002\u793a\u4f8b\u4ee3\u7801\uff1a int[] oldArray = {1, 2, 3}; ArrayList&lt;Integer&gt; arrayList = new ArrayList&lt;&gt;(Arrays.asList(oldArray)); arrayList.add(4); arrayList.add(5); int[] newArray = arrayList.stream().mapToInt(Integer::intValue).toArray(); [&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-65558","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/65558","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=65558"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/65558\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=65558"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=65558"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=65558"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}