{"id":39210,"date":"2024-11-26T17:26:21","date_gmt":"2024-11-26T09:26:21","guid":{"rendered":"https:\/\/fwq.ai\/blog\/39210\/"},"modified":"2024-11-26T17:26:21","modified_gmt":"2024-11-26T09:26:21","slug":"java%e6%95%b0%e7%bb%84%e6%80%8e%e4%b9%88%e6%b8%85%e9%99%a4%e4%b8%80%e4%b8%aa%e9%95%bf%e5%ba%a6","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/39210\/","title":{"rendered":"java\u6570\u7ec4\u600e\u4e48\u6e05\u9664\u4e00\u4e2a\u957f\u5ea6"},"content":{"rendered":"<blockquote><p>\n  java \u6570\u7ec4\u7684\u957f\u5ea6\u65e0\u6cd5\u76f4\u63a5\u6e05\u9664\uff0c\u4f46\u53ef\u901a\u8fc7\u4ee5\u4e0b\u65b9\u5f0f\u5b9e\u73b0\u7c7b\u4f3c\u6548\u679c\uff1a1. \u91cd\u65b0\u5206\u914d\u6570\u7ec4\uff1b2. \u4f7f\u7528 list \u5c06\u6570\u7ec4\u5143\u7d20\u590d\u5236\u5e76\u6e05\u9664\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/16\/2024111605210929301.jpg\" class=\"aligncenter\" title=\"java\u6570\u7ec4\u600e\u4e48\u6e05\u9664\u4e00\u4e2a\u957f\u5ea6\u63d2\u56fe\" alt=\"java\u6570\u7ec4\u600e\u4e48\u6e05\u9664\u4e00\u4e2a\u957f\u5ea6\u63d2\u56fe\" \/><\/p>\n<h2>\u5982\u4f55\u6e05\u9664 Java \u6570\u7ec4\u7684\u957f\u5ea6<\/h2>\n<p>Java \u6570\u7ec4\u662f\u4e00\u4e2a\u56fa\u5b9a\u957f\u5ea6\u7684\u6570\u636e\u7ed3\u6784\uff0c\u4e00\u65e6\u521b\u5efa\uff0c\u6570\u7ec4\u7684\u957f\u5ea6\u5c31\u65e0\u6cd5\u66f4\u6539\u3002\u56e0\u6b64\uff0c\u65e0\u6cd5\u76f4\u63a5\u6e05\u9664\u6570\u7ec4\u7684\u957f\u5ea6\u3002\u7136\u800c\uff0c\u6709\u4ee5\u4e0b\u66ff\u4ee3\u65b9\u6848\u53ef\u4ee5\u5b9e\u73b0\u7c7b\u4f3c\u7684\u6548\u679c\uff1a<\/p>\n<p><strong>1. \u91cd\u65b0\u5206\u914d\u6570\u7ec4<\/strong><\/p>\n<p>\u60a8\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u65b0\u6570\u7ec4\uff0c\u5176\u957f\u5ea6\u4e0e\u6240\u9700\u7684\u957f\u5ea6\u76f8\u5339\u914d\uff0c\u7136\u540e\u5c06\u539f\u59cb\u6570\u7ec4\u4e2d\u7684\u5143\u7d20\u590d\u5236\u5230\u65b0\u6570\u7ec4\u4e2d\u3002\u8fd9\u5c06\u6e05\u9664\u539f\u59cb\u6570\u7ec4\u7684\u957f\u5ea6\uff0c\u56e0\u4e3a\u5b83\u5c06\u4e0d\u518d\u4f7f\u7528\u3002<\/p>\n<pre>int[] oldArray = {1, 2, 3, 4, 5};\nint[] newArray = new int[3];\nSystem.arraycopy(oldArray, 0, newArray, 0, 3);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>2. \u4f7f\u7528 List<\/strong><\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<p>List \u662f Java \u4e2d\u4e00\u4e2a\u52a8\u6001\u5927\u5c0f\u7684\u6570\u636e\u7ed3\u6784\uff0c\u5b83\u5141\u8bb8\u60a8\u6dfb\u52a0\u548c\u5220\u9664\u5143\u7d20\u3002\u60a8\u53ef\u4ee5\u5c06\u6570\u7ec4\u5143\u7d20\u590d\u5236\u5230 List \u4e2d\uff0c\u7136\u540e\u4f7f\u7528 List \u7684 clear() \u65b9\u6cd5\u6e05\u9664 List \u7684\u5185\u5bb9\u3002\u8fd9\u5c06\u6709\u6548\u5730\u6e05\u9664\u6570\u7ec4\u7684\u957f\u5ea6\u3002<\/p>\n<pre>int[] oldArray = {1, 2, 3, 4, 5};\nList&lt;Integer&gt; list = new ArrayList&lt;&gt;();\nlist.addAll(Arrays.asList(oldArray));\nlist.clear();<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fjava\u6570\u7ec4\u600e\u4e48\u6e05\u9664\u4e00\u4e2a\u957f\u5ea6\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>java \u6570\u7ec4\u7684\u957f\u5ea6\u65e0\u6cd5\u76f4\u63a5\u6e05\u9664\uff0c\u4f46\u53ef\u901a\u8fc7\u4ee5\u4e0b\u65b9\u5f0f\u5b9e\u73b0\u7c7b\u4f3c\u6548\u679c\uff1a1. \u91cd\u65b0\u5206\u914d\u6570\u7ec4\uff1b2. \u4f7f\u7528 list \u5c06\u6570\u7ec4\u5143\u7d20\u590d\u5236\u5e76\u6e05\u9664\u3002 \u5982\u4f55\u6e05\u9664 Java \u6570\u7ec4\u7684\u957f\u5ea6 Java \u6570\u7ec4\u662f\u4e00\u4e2a\u56fa\u5b9a\u957f\u5ea6\u7684\u6570\u636e\u7ed3\u6784\uff0c\u4e00\u65e6\u521b\u5efa\uff0c\u6570\u7ec4\u7684\u957f\u5ea6\u5c31\u65e0\u6cd5\u66f4\u6539\u3002\u56e0\u6b64\uff0c\u65e0\u6cd5\u76f4\u63a5\u6e05\u9664\u6570\u7ec4\u7684\u957f\u5ea6\u3002\u7136\u800c\uff0c\u6709\u4ee5\u4e0b\u66ff\u4ee3\u65b9\u6848\u53ef\u4ee5\u5b9e\u73b0\u7c7b\u4f3c\u7684\u6548\u679c\uff1a 1. \u91cd\u65b0\u5206\u914d\u6570\u7ec4 \u60a8\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u65b0\u6570\u7ec4\uff0c\u5176\u957f\u5ea6\u4e0e\u6240\u9700\u7684\u957f\u5ea6\u76f8\u5339\u914d\uff0c\u7136\u540e\u5c06\u539f\u59cb\u6570\u7ec4\u4e2d\u7684\u5143\u7d20\u590d\u5236\u5230\u65b0\u6570\u7ec4\u4e2d\u3002\u8fd9\u5c06\u6e05\u9664\u539f\u59cb\u6570\u7ec4\u7684\u957f\u5ea6\uff0c\u56e0\u4e3a\u5b83\u5c06\u4e0d\u518d\u4f7f\u7528\u3002 int[] oldArray = {1, 2, 3, 4, 5}; int[] newArray = new int[3]; System.arraycopy(oldArray, 0, newArray, 0, 3); \u767b\u5f55\u540e\u590d\u5236 2. \u4f7f\u7528 List \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b List \u662f Java \u4e2d\u4e00\u4e2a\u52a8\u6001\u5927\u5c0f\u7684\u6570\u636e\u7ed3\u6784\uff0c\u5b83\u5141\u8bb8\u60a8\u6dfb\u52a0\u548c\u5220\u9664\u5143\u7d20\u3002\u60a8\u53ef\u4ee5\u5c06\u6570\u7ec4\u5143\u7d20\u590d\u5236\u5230 List \u4e2d\uff0c\u7136\u540e\u4f7f\u7528 List \u7684 clear() \u65b9\u6cd5\u6e05\u9664 List \u7684\u5185\u5bb9\u3002\u8fd9\u5c06\u6709\u6548\u5730\u6e05\u9664\u6570\u7ec4\u7684\u957f\u5ea6\u3002 int[] oldArray = {1, 2, 3, [&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-39210","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/39210","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=39210"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/39210\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=39210"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=39210"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=39210"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}