{"id":36884,"date":"2024-11-26T13:56:05","date_gmt":"2024-11-26T05:56:05","guid":{"rendered":"https:\/\/fwq.ai\/blog\/36884\/"},"modified":"2024-11-26T13:56:05","modified_gmt":"2024-11-26T05:56:05","slug":"java%e4%b8%ad%e6%95%b0%e7%bb%84%e6%80%8e%e4%b9%88%e6%89%a9%e5%ae%b9","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/36884\/","title":{"rendered":"java\u4e2d\u6570\u7ec4\u600e\u4e48\u6269\u5bb9"},"content":{"rendered":"<blockquote><p>\n  java\u4e2d\u6570\u7ec4\u6269\u5bb9\u7684\u65b9\u6cd5\u662f\u521b\u5efa\u4e00\u4e2a\u65b0\u6570\u7ec4\uff0c\u5176\u5927\u5c0f\u5927\u4e8e\u539f\u6570\u7ec4\uff0c\u7136\u540e\u5c06\u539f\u6570\u7ec4\u7684\u5143\u7d20\u590d\u5236\u5230\u65b0\u6570\u7ec4\u4e2d\uff0c\u6700\u540e\u7528\u65b0\u6570\u7ec4\u66ff\u6362\u539f\u6570\u7ec4\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/12\/2024111220541733973.jpg\" class=\"aligncenter\" title=\"java\u4e2d\u6570\u7ec4\u600e\u4e48\u6269\u5bb9\u63d2\u56fe\" alt=\"java\u4e2d\u6570\u7ec4\u600e\u4e48\u6269\u5bb9\u63d2\u56fe\" \/><\/p>\n<p><strong>Java\u6570\u7ec4\u6269\u5bb9<\/strong><\/p>\n<p>\u5728Java\u4e2d\uff0c\u6570\u7ec4\u662f\u4e00\u79cd\u56fa\u5b9a\u5927\u5c0f\u7684\u6570\u636e\u7ed3\u6784\uff0c\u4e00\u65e6\u521b\u5efa\u540e\uff0c\u5176\u5927\u5c0f\u4e0d\u53ef\u66f4\u6539\u3002\u56e0\u6b64\uff0c\u5f53\u9700\u8981\u5b58\u50a8\u8d85\u8fc7\u6570\u7ec4\u521d\u59cb\u5bb9\u91cf\u7684\u6570\u636e\u65f6\uff0c\u5c31\u9700\u8981\u8fdb\u884c\u6570\u7ec4\u6269\u5bb9\u3002<\/p>\n<p><strong>\u5982\u4f55\u6269\u5bb9\u6570\u7ec4<\/strong><\/p>\n<p>Java\u4e2d\u6ca1\u6709\u5185\u7f6e\u7684\u6570\u7ec4\u6269\u5bb9\u64cd\u4f5c\u3002\u8981\u6269\u5bb9\u6570\u7ec4\uff0c\u9700\u8981\u521b\u5efa\u4e00\u4e2a\u65b0\u6570\u7ec4\uff0c\u5176\u5927\u5c0f\u5927\u4e8e\u539f\u6570\u7ec4\uff0c\u7136\u540e\u5c06\u539f\u6570\u7ec4\u4e2d\u7684\u5143\u7d20\u590d\u5236\u5230\u65b0\u6570\u7ec4\u4e2d\u3002<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<p>\u4ee5\u4e0b\u662f\u5982\u4f55\u5728Java\u4e2d\u6269\u5bb9\u6570\u7ec4\u7684\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<pre>int[] original = {1, 2, 3, 4, 5};\nint newSize = original.length * 2;\nint[] expanded = new int[newSize];\n\n\/\/ \u5c06\u539f\u6570\u7ec4\u4e2d\u7684\u5143\u7d20\u590d\u5236\u5230\u65b0\u6570\u7ec4\u4e2d\nfor (int i = 0; i &lt; original.length; i++) {\n    expanded[i] = original[i];\n}\n\n\/\/ \u66ff\u6362\u539f\u6570\u7ec4\noriginal = expanded;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5728\u4e0a\u9762\u7684\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u521b\u5efa\u4e86\u4e00\u4e2a\u540d\u4e3aoriginal\u7684\u6570\u7ec4\uff0c\u5305\u542b5\u4e2a\u5143\u7d20\u3002\u7136\u540e\uff0c\u6211\u4eec\u521b\u5efa\u4e86\u4e00\u4e2a\u5927\u5c0f\u4e3a10\u7684\u65b0\u6570\u7ec4expanded\uff0c\u5e76\u5c06original\u4e2d\u7684\u5143\u7d20\u590d\u5236\u5230expanded\u4e2d\u3002\u6700\u540e\uff0c\u6211\u4eec\u7528expanded\u66ff\u6362original\u3002<\/p>\n<p><strong>\u6ce8\u610f\u4e8b\u9879<\/strong><\/p>\n<ul>\n<li>\u6269\u5bb9\u6570\u7ec4\u65f6\uff0c\u65b0\u6570\u7ec4\u7684\u5927\u5c0f\u5e94\u5927\u4e8e\u7b49\u4e8e\u539f\u6570\u7ec4\u7684\u5927\u5c0f\u3002<\/li>\n<li>\u590d\u5236\u539f\u6570\u7ec4\u4e2d\u7684\u5143\u7d20\u65f6\uff0c\u786e\u4fdd\u5faa\u73af\u6761\u4ef6\u6b63\u786e\uff0c\u4ee5\u514d\u6570\u7ec4\u8d8a\u754c\u3002<\/li>\n<li>\u6269\u5bb9\u6570\u7ec4\u662f\u4e00\u4e2a\u8017\u65f6\u7684\u64cd\u4f5c\uff0c\u56e0\u6b64\uff0c\u5728\u9891\u7e41\u6269\u5bb9\u6570\u7ec4\u7684\u573a\u666f\u4e2d\uff0c\u5e94\u8003\u8651\u4f7f\u7528\u5176\u4ed6\u6570\u636e\u7ed3\u6784\uff0c\u5982ArrayList\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662fjava\u4e2d\u6570\u7ec4\u600e\u4e48\u6269\u5bb9\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\u6269\u5bb9\u7684\u65b9\u6cd5\u662f\u521b\u5efa\u4e00\u4e2a\u65b0\u6570\u7ec4\uff0c\u5176\u5927\u5c0f\u5927\u4e8e\u539f\u6570\u7ec4\uff0c\u7136\u540e\u5c06\u539f\u6570\u7ec4\u7684\u5143\u7d20\u590d\u5236\u5230\u65b0\u6570\u7ec4\u4e2d\uff0c\u6700\u540e\u7528\u65b0\u6570\u7ec4\u66ff\u6362\u539f\u6570\u7ec4\u3002 Java\u6570\u7ec4\u6269\u5bb9 \u5728Java\u4e2d\uff0c\u6570\u7ec4\u662f\u4e00\u79cd\u56fa\u5b9a\u5927\u5c0f\u7684\u6570\u636e\u7ed3\u6784\uff0c\u4e00\u65e6\u521b\u5efa\u540e\uff0c\u5176\u5927\u5c0f\u4e0d\u53ef\u66f4\u6539\u3002\u56e0\u6b64\uff0c\u5f53\u9700\u8981\u5b58\u50a8\u8d85\u8fc7\u6570\u7ec4\u521d\u59cb\u5bb9\u91cf\u7684\u6570\u636e\u65f6\uff0c\u5c31\u9700\u8981\u8fdb\u884c\u6570\u7ec4\u6269\u5bb9\u3002 \u5982\u4f55\u6269\u5bb9\u6570\u7ec4 Java\u4e2d\u6ca1\u6709\u5185\u7f6e\u7684\u6570\u7ec4\u6269\u5bb9\u64cd\u4f5c\u3002\u8981\u6269\u5bb9\u6570\u7ec4\uff0c\u9700\u8981\u521b\u5efa\u4e00\u4e2a\u65b0\u6570\u7ec4\uff0c\u5176\u5927\u5c0f\u5927\u4e8e\u539f\u6570\u7ec4\uff0c\u7136\u540e\u5c06\u539f\u6570\u7ec4\u4e2d\u7684\u5143\u7d20\u590d\u5236\u5230\u65b0\u6570\u7ec4\u4e2d\u3002 \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b \u4ee5\u4e0b\u662f\u5982\u4f55\u5728Java\u4e2d\u6269\u5bb9\u6570\u7ec4\u7684\u793a\u4f8b\u4ee3\u7801\uff1a int[] original = {1, 2, 3, 4, 5}; int newSize = original.length * 2; int[] expanded = new int[newSize]; \/\/ \u5c06\u539f\u6570\u7ec4\u4e2d\u7684\u5143\u7d20\u590d\u5236\u5230\u65b0\u6570\u7ec4\u4e2d for (int i = 0; i &lt; original.length; i++) { expanded[i] = original[i]; } \/\/ \u66ff\u6362\u539f\u6570\u7ec4 original = expanded; \u767b\u5f55\u540e\u590d\u5236 \u5728\u4e0a\u9762\u7684\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u521b\u5efa\u4e86\u4e00\u4e2a\u540d\u4e3aoriginal\u7684\u6570\u7ec4\uff0c\u5305\u542b5\u4e2a\u5143\u7d20\u3002\u7136\u540e\uff0c\u6211\u4eec\u521b\u5efa\u4e86\u4e00\u4e2a\u5927\u5c0f\u4e3a10\u7684\u65b0\u6570\u7ec4expanded\uff0c\u5e76\u5c06original\u4e2d\u7684\u5143\u7d20\u590d\u5236\u5230expanded\u4e2d\u3002\u6700\u540e\uff0c\u6211\u4eec\u7528expanded\u66ff\u6362original\u3002 \u6ce8\u610f\u4e8b\u9879 \u6269\u5bb9\u6570\u7ec4\u65f6\uff0c\u65b0\u6570\u7ec4\u7684\u5927\u5c0f\u5e94\u5927\u4e8e\u7b49\u4e8e\u539f\u6570\u7ec4\u7684\u5927\u5c0f\u3002 \u590d\u5236\u539f\u6570\u7ec4\u4e2d\u7684\u5143\u7d20\u65f6\uff0c\u786e\u4fdd\u5faa\u73af\u6761\u4ef6\u6b63\u786e\uff0c\u4ee5\u514d\u6570\u7ec4\u8d8a\u754c\u3002 \u6269\u5bb9\u6570\u7ec4\u662f\u4e00\u4e2a\u8017\u65f6\u7684\u64cd\u4f5c\uff0c\u56e0\u6b64\uff0c\u5728\u9891\u7e41\u6269\u5bb9\u6570\u7ec4\u7684\u573a\u666f\u4e2d\uff0c\u5e94\u8003\u8651\u4f7f\u7528\u5176\u4ed6\u6570\u636e\u7ed3\u6784\uff0c\u5982ArrayList\u3002 \u4ee5\u4e0a\u5c31\u662fjava\u4e2d\u6570\u7ec4\u600e\u4e48\u6269\u5bb9\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/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-36884","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/36884","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=36884"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/36884\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=36884"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=36884"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=36884"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}