{"id":34406,"date":"2024-11-26T17:06:08","date_gmt":"2024-11-26T09:06:08","guid":{"rendered":"https:\/\/fwq.ai\/blog\/34406\/"},"modified":"2024-11-26T17:06:08","modified_gmt":"2024-11-26T09:06:08","slug":"java%e5%87%8f%e5%b0%91%e6%95%b0%e7%bb%84%e7%9a%84%e9%95%bf%e5%ba%a6%e6%80%8e%e4%b9%88%e5%86%99","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/34406\/","title":{"rendered":"java\u51cf\u5c11\u6570\u7ec4\u7684\u957f\u5ea6\u600e\u4e48\u5199"},"content":{"rendered":"<blockquote><p>\n  java \u4e2d\u6570\u7ec4\u7684\u957f\u5ea6\u4e00\u65e6\u521b\u5efa\u5c31\u4e0d\u53ef\u66f4\u6539\uff0c\u4f46\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u6b65\u9aa4\u51cf\u5c11\u5176\u903b\u8f91\u957f\u5ea6\uff1a\u521b\u5efa\u65b0\u6570\u7ec4\uff0c\u957f\u5ea6\u6bd4\u539f\u59cb\u6570\u7ec4\u5c0f\u3002\u4f7f\u7528 system.arraycopy() \u590d\u5236\u5143\u7d20\u5230\u65b0\u6570\u7ec4\u3002\u5c06\u539f\u59cb\u6570\u7ec4\u66ff\u6362\u4e3a\u65b0\u6570\u7ec4\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/02\/2024110209451938311.jpg\" class=\"aligncenter\" title=\"java\u51cf\u5c11\u6570\u7ec4\u7684\u957f\u5ea6\u600e\u4e48\u5199\u63d2\u56fe\" alt=\"java\u51cf\u5c11\u6570\u7ec4\u7684\u957f\u5ea6\u600e\u4e48\u5199\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u51cf\u5c11 Java \u6570\u7ec4\u7684\u957f\u5ea6\uff1f<\/strong><\/p>\n<p>\u5728 Java \u4e2d\uff0c\u6570\u7ec4\u7684\u5927\u5c0f\u662f\u56fa\u5b9a\u7684\uff0c\u4e00\u65e6\u521b\u5efa\u5c31\u4e0d\u80fd\u66f4\u6539\u3002\u7136\u800c\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u6b65\u9aa4\u6765\u51cf\u5c11\u6570\u7ec4\u7684\u903b\u8f91\u957f\u5ea6\uff1a<\/p>\n<p><strong>\u6b65\u9aa4 1\uff1a\u521b\u5efa\u65b0\u6570\u7ec4<\/strong><\/p>\n<p>\u521b\u5efa\u4e00\u4e2a\u65b0\u6570\u7ec4\uff0c\u5176\u957f\u5ea6\u6bd4\u539f\u59cb\u6570\u7ec4\u5c0f\u3002<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<pre>int[] newArray = new int[newLength];<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u6b65\u9aa4 2\uff1a\u590d\u5236\u5143\u7d20<\/strong><\/p>\n<p>\u4f7f\u7528 System.arraycopy() \u65b9\u6cd5\u5c06\u5143\u7d20\u4ece\u539f\u59cb\u6570\u7ec4\u590d\u5236\u5230\u65b0\u6570\u7ec4\u3002<\/p>\n<pre>System.arraycopy(originalArray, 0, newArray, 0, newLength);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u6b65\u9aa4 3\uff1a\u5c06\u539f\u59cb\u6570\u7ec4\u66ff\u6362\u4e3a\u65b0\u6570\u7ec4<\/strong><\/p>\n<p>\u5c06\u539f\u59cb\u6570\u7ec4\u5f15\u7528\u66ff\u6362\u4e3a\u65b0\u6570\u7ec4\u7684\u5f15\u7528\u3002<\/p>\n<pre>originalArray = newArray;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre>int[] originalArray = {1, 2, 3, 4, 5};\nint newLength = 3;\n\n\/\/ \u521b\u5efa\u65b0\u6570\u7ec4\nint[] newArray = new int[newLength];\n\n\/\/ \u590d\u5236\u5143\u7d20\nSystem.arraycopy(originalArray, 0, newArray, 0, newLength);\n\n\/\/ \u66ff\u6362\u539f\u59cb\u6570\u7ec4\noriginalArray = newArray;\n\n\/\/ \u6253\u5370\u65b0\u6570\u7ec4\nfor (int i : originalArray) {\n    System.out.println(i); \/\/ \u8f93\u51fa\uff1a1, 2, 3\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fjava\u51cf\u5c11\u6570\u7ec4\u7684\u957f\u5ea6\u600e\u4e48\u5199\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 \u4e2d\u6570\u7ec4\u7684\u957f\u5ea6\u4e00\u65e6\u521b\u5efa\u5c31\u4e0d\u53ef\u66f4\u6539\uff0c\u4f46\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u6b65\u9aa4\u51cf\u5c11\u5176\u903b\u8f91\u957f\u5ea6\uff1a\u521b\u5efa\u65b0\u6570\u7ec4\uff0c\u957f\u5ea6\u6bd4\u539f\u59cb\u6570\u7ec4\u5c0f\u3002\u4f7f\u7528 system.arraycopy() \u590d\u5236\u5143\u7d20\u5230\u65b0\u6570\u7ec4\u3002\u5c06\u539f\u59cb\u6570\u7ec4\u66ff\u6362\u4e3a\u65b0\u6570\u7ec4\u3002 \u5982\u4f55\u51cf\u5c11 Java \u6570\u7ec4\u7684\u957f\u5ea6\uff1f \u5728 Java \u4e2d\uff0c\u6570\u7ec4\u7684\u5927\u5c0f\u662f\u56fa\u5b9a\u7684\uff0c\u4e00\u65e6\u521b\u5efa\u5c31\u4e0d\u80fd\u66f4\u6539\u3002\u7136\u800c\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u6b65\u9aa4\u6765\u51cf\u5c11\u6570\u7ec4\u7684\u903b\u8f91\u957f\u5ea6\uff1a \u6b65\u9aa4 1\uff1a\u521b\u5efa\u65b0\u6570\u7ec4 \u521b\u5efa\u4e00\u4e2a\u65b0\u6570\u7ec4\uff0c\u5176\u957f\u5ea6\u6bd4\u539f\u59cb\u6570\u7ec4\u5c0f\u3002 \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b int[] newArray = new int[newLength]; \u767b\u5f55\u540e\u590d\u5236 \u6b65\u9aa4 2\uff1a\u590d\u5236\u5143\u7d20 \u4f7f\u7528 System.arraycopy() \u65b9\u6cd5\u5c06\u5143\u7d20\u4ece\u539f\u59cb\u6570\u7ec4\u590d\u5236\u5230\u65b0\u6570\u7ec4\u3002 System.arraycopy(originalArray, 0, newArray, 0, newLength); \u767b\u5f55\u540e\u590d\u5236 \u6b65\u9aa4 3\uff1a\u5c06\u539f\u59cb\u6570\u7ec4\u66ff\u6362\u4e3a\u65b0\u6570\u7ec4 \u5c06\u539f\u59cb\u6570\u7ec4\u5f15\u7528\u66ff\u6362\u4e3a\u65b0\u6570\u7ec4\u7684\u5f15\u7528\u3002 originalArray = newArray; \u767b\u5f55\u540e\u590d\u5236 \u793a\u4f8b\uff1a int[] originalArray = {1, 2, 3, 4, 5}; int newLength = 3; \/\/ \u521b\u5efa\u65b0\u6570\u7ec4 int[] newArray [&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-34406","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/34406","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=34406"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/34406\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=34406"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=34406"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=34406"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}