{"id":66221,"date":"2025-05-03T17:01:22","date_gmt":"2025-05-03T09:01:22","guid":{"rendered":"https:\/\/fwq.ai\/blog\/66221\/"},"modified":"2025-05-03T17:01:22","modified_gmt":"2025-05-03T09:01:22","slug":"java%e6%80%8e%e4%b9%88%e6%b7%bb%e5%8a%a0%e5%85%83%e7%b4%a0%e5%88%b0%e6%95%b0%e7%bb%84%e9%87%8c-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/66221\/","title":{"rendered":"java\u600e\u4e48\u6dfb\u52a0\u5143\u7d20\u5230\u6570\u7ec4\u91cc"},"content":{"rendered":"<blockquote><p>\n  \u5728 java \u4e2d\uff0c\u65e0\u6cd5\u52a8\u6001\u6269\u5145\u6570\u7ec4\uff0c\u6dfb\u52a0\u5143\u7d20\u9700\u8981\u521b\u5efa\u65b0\u6570\u7ec4\u3002\u5177\u4f53\u6b65\u9aa4\uff1a\u521b\u5efa\u65b0\u6570\u7ec4\uff0c\u957f\u5ea6\u6bd4\u539f\u6570\u7ec4\u66f4\u5927\u3002\u590d\u5236\u539f\u6570\u7ec4\u5143\u7d20\u5230\u65b0\u6570\u7ec4\u3002\u6dfb\u52a0\u65b0\u5143\u7d20\u5230\u65b0\u6570\u7ec4\u3002\u8ba9\u6570\u7ec4\u53d8\u91cf\u5f15\u7528\u65b0\u6570\u7ec4\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/15\/2024111504181992473.jpg\" class=\"aligncenter\" title=\"java\u600e\u4e48\u6dfb\u52a0\u5143\u7d20\u5230\u6570\u7ec4\u91cc\u63d2\u56fe\" alt=\"java\u600e\u4e48\u6dfb\u52a0\u5143\u7d20\u5230\u6570\u7ec4\u91cc\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u5411 Java \u6570\u7ec4\u4e2d\u6dfb\u52a0\u5143\u7d20<\/strong><\/p>\n<p>\u5728 Java \u4e2d\uff0c\u6570\u7ec4\u7684\u957f\u5ea6\u5728\u521b\u5efa\u65f6\u56fa\u5b9a\uff0c\u65e0\u6cd5\u8fdb\u884c\u52a8\u6001\u6269\u5145\u3002\u56e0\u6b64\uff0c\u4e3a\u4e86\u5411\u6570\u7ec4\u4e2d\u6dfb\u52a0\u5143\u7d20\uff0c\u5e38\u7528\u7684\u65b9\u6cd5\u662f\u5728\u539f\u6570\u7ec4\u7684\u57fa\u7840\u4e0a\uff0c\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u3001\u66f4\u5927\u7684\u6570\u7ec4\uff0c\u7136\u540e\u5c06\u539f\u6570\u7ec4\u4e2d\u7684\u5143\u7d20\u590d\u5236\u5230\u65b0\u7684\u6570\u7ec4\u4e2d\uff0c\u518d\u5c06\u8981\u6dfb\u52a0\u7684\u5143\u7d20\u6dfb\u52a0\u5230\u65b0\u7684\u6570\u7ec4\u4e2d\u3002<\/p>\n<p><strong>\u5177\u4f53\u6b65\u9aa4\uff1a<\/strong><\/p>\n<ol>\n<li> <strong>\u521b\u5efa\u65b0\u6570\u7ec4\uff1a<\/strong>\u5148\u521b\u5efa\u4e00\u4e2a\u65b0\u6570\u7ec4\uff0c\u957f\u5ea6\u6bd4\u539f\u6570\u7ec4\u5927 1\uff08\u6216\u66f4\u5927\uff0c\u4ee5\u6ee1\u8db3\u9700\u8981\uff09\u3002<\/li>\n<li> <strong>\u590d\u5236\u539f\u6570\u7ec4\uff1a<\/strong>\u4f7f\u7528 System.arraycopy() \u65b9\u6cd5\uff0c\u5c06\u539f\u6570\u7ec4\u4e2d\u7684\u5143\u7d20\u590d\u5236\u5230\u65b0\u6570\u7ec4\u4e2d\u3002<\/li>\n<li> <strong>\u6dfb\u52a0\u65b0\u5143\u7d20\uff1a<\/strong>\u5728\u65b0\u6570\u7ec4\u4e2d\uff0c\u7d22\u5f15\u4e3a\u539f\u6570\u7ec4\u957f\u5ea6\u7684\u4f4d\u7f6e\u6dfb\u52a0\u8981\u6dfb\u52a0\u7684\u65b0\u5143\u7d20\u3002<\/li>\n<li> <strong>\u5f15\u7528\u65b0\u6570\u7ec4\uff1a<\/strong>\u6700\u540e\uff0c\u8ba9\u6570\u7ec4\u53d8\u91cf\u5f15\u7528\u65b0\u6570\u7ec4\uff0c\u8fd9\u6837\u539f\u6570\u7ec4\u5c31\u5305\u542b\u4e86\u6dfb\u52a0\u540e\u7684\u5143\u7d20\u3002<\/li>\n<\/ol>\n<p><strong>\u4ee3\u7801\u793a\u4f8b\uff1a<\/strong><\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<p>\u5047\u8bbe\u6211\u4eec\u6709\u4e00\u4e2a\u540d\u4e3a nums \u7684\u6570\u7ec4\uff0c\u5305\u542b\u5143\u7d20 {1, 2, 3}\uff0c\u73b0\u5728\u6211\u4eec\u8981\u5411\u5176\u4e2d\u6dfb\u52a0\u4e00\u4e2a\u5143\u7d20 4\u3002<\/p>\n<pre>\/\/ \u521b\u5efa\u65b0\u6570\u7ec4\nint[] newArr = new int[nums.length + 1];\n\n\/\/ \u590d\u5236\u539f\u6570\u7ec4\nSystem.arraycopy(nums, 0, newArr, 0, nums.length);\n\n\/\/ \u6dfb\u52a0\u65b0\u5143\u7d20\nnewArr[nums.length] = 4;\n\n\/\/ \u5f15\u7528\u65b0\u6570\u7ec4\nnums = newArr;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u73b0\u5728\uff0c\u6570\u7ec4 nums \u5c31\u5305\u542b\u4e86\u6dfb\u52a0\u540e\u7684\u5143\u7d20 {1, 2, 3, 4}\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fjava\u600e\u4e48\u6dfb\u52a0\u5143\u7d20\u5230\u6570\u7ec4\u91cc\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>\u5728 java \u4e2d\uff0c\u65e0\u6cd5\u52a8\u6001\u6269\u5145\u6570\u7ec4\uff0c\u6dfb\u52a0\u5143\u7d20\u9700\u8981\u521b\u5efa\u65b0\u6570\u7ec4\u3002\u5177\u4f53\u6b65\u9aa4\uff1a\u521b\u5efa\u65b0\u6570\u7ec4\uff0c\u957f\u5ea6\u6bd4\u539f\u6570\u7ec4\u66f4\u5927\u3002\u590d\u5236\u539f\u6570\u7ec4\u5143\u7d20\u5230\u65b0\u6570\u7ec4\u3002\u6dfb\u52a0\u65b0\u5143\u7d20\u5230\u65b0\u6570\u7ec4\u3002\u8ba9\u6570\u7ec4\u53d8\u91cf\u5f15\u7528\u65b0\u6570\u7ec4\u3002 \u5982\u4f55\u5411 Java \u6570\u7ec4\u4e2d\u6dfb\u52a0\u5143\u7d20 \u5728 Java \u4e2d\uff0c\u6570\u7ec4\u7684\u957f\u5ea6\u5728\u521b\u5efa\u65f6\u56fa\u5b9a\uff0c\u65e0\u6cd5\u8fdb\u884c\u52a8\u6001\u6269\u5145\u3002\u56e0\u6b64\uff0c\u4e3a\u4e86\u5411\u6570\u7ec4\u4e2d\u6dfb\u52a0\u5143\u7d20\uff0c\u5e38\u7528\u7684\u65b9\u6cd5\u662f\u5728\u539f\u6570\u7ec4\u7684\u57fa\u7840\u4e0a\uff0c\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u3001\u66f4\u5927\u7684\u6570\u7ec4\uff0c\u7136\u540e\u5c06\u539f\u6570\u7ec4\u4e2d\u7684\u5143\u7d20\u590d\u5236\u5230\u65b0\u7684\u6570\u7ec4\u4e2d\uff0c\u518d\u5c06\u8981\u6dfb\u52a0\u7684\u5143\u7d20\u6dfb\u52a0\u5230\u65b0\u7684\u6570\u7ec4\u4e2d\u3002 \u5177\u4f53\u6b65\u9aa4\uff1a \u521b\u5efa\u65b0\u6570\u7ec4\uff1a\u5148\u521b\u5efa\u4e00\u4e2a\u65b0\u6570\u7ec4\uff0c\u957f\u5ea6\u6bd4\u539f\u6570\u7ec4\u5927 1\uff08\u6216\u66f4\u5927\uff0c\u4ee5\u6ee1\u8db3\u9700\u8981\uff09\u3002 \u590d\u5236\u539f\u6570\u7ec4\uff1a\u4f7f\u7528 System.arraycopy() \u65b9\u6cd5\uff0c\u5c06\u539f\u6570\u7ec4\u4e2d\u7684\u5143\u7d20\u590d\u5236\u5230\u65b0\u6570\u7ec4\u4e2d\u3002 \u6dfb\u52a0\u65b0\u5143\u7d20\uff1a\u5728\u65b0\u6570\u7ec4\u4e2d\uff0c\u7d22\u5f15\u4e3a\u539f\u6570\u7ec4\u957f\u5ea6\u7684\u4f4d\u7f6e\u6dfb\u52a0\u8981\u6dfb\u52a0\u7684\u65b0\u5143\u7d20\u3002 \u5f15\u7528\u65b0\u6570\u7ec4\uff1a\u6700\u540e\uff0c\u8ba9\u6570\u7ec4\u53d8\u91cf\u5f15\u7528\u65b0\u6570\u7ec4\uff0c\u8fd9\u6837\u539f\u6570\u7ec4\u5c31\u5305\u542b\u4e86\u6dfb\u52a0\u540e\u7684\u5143\u7d20\u3002 \u4ee3\u7801\u793a\u4f8b\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b \u5047\u8bbe\u6211\u4eec\u6709\u4e00\u4e2a\u540d\u4e3a nums \u7684\u6570\u7ec4\uff0c\u5305\u542b\u5143\u7d20 {1, 2, 3}\uff0c\u73b0\u5728\u6211\u4eec\u8981\u5411\u5176\u4e2d\u6dfb\u52a0\u4e00\u4e2a\u5143\u7d20 4\u3002 \/\/ \u521b\u5efa\u65b0\u6570\u7ec4 int[] newArr = new int[nums.length + 1]; \/\/ \u590d\u5236\u539f\u6570\u7ec4 System.arraycopy(nums, 0, newArr, 0, nums.length); \/\/ \u6dfb\u52a0\u65b0\u5143\u7d20 newArr[nums.length] = 4; \/\/ \u5f15\u7528\u65b0\u6570\u7ec4 nums = newArr; \u767b\u5f55\u540e\u590d\u5236 \u73b0\u5728\uff0c\u6570\u7ec4 nums [&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-66221","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/66221","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=66221"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/66221\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=66221"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=66221"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=66221"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}