{"id":40065,"date":"2024-11-26T15:30:27","date_gmt":"2024-11-26T07:30:27","guid":{"rendered":"https:\/\/fwq.ai\/blog\/40065\/"},"modified":"2024-11-26T15:30:27","modified_gmt":"2024-11-26T07:30:27","slug":"java%e6%80%8e%e4%b9%88%e5%88%a0%e9%99%a4%e6%95%b0%e7%bb%84%e4%b8%ad%e4%b8%80%e5%88%97%e6%95%b0%e6%8d%ae","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/40065\/","title":{"rendered":"java\u600e\u4e48\u5220\u9664\u6570\u7ec4\u4e2d\u4e00\u5217\u6570\u636e"},"content":{"rendered":"<blockquote><p>\n  \u6709\u56db\u79cd\u65b9\u6cd5\u53ef\u4ee5\u5220\u9664 java \u6570\u7ec4\u4e2d\u7684\u4e00\u5217\u6570\u636e\uff1a\u4f7f\u7528 system.arraycopy() \u590d\u5236\u6570\u7ec4\u7684\u6bcf\u4e00\u884c\uff0c\u8df3\u8fc7\u8981\u5220\u9664\u7684\u5217\u3002\u4f7f\u7528 guava \u5e93\u904d\u5386\u6bcf\u4e00\u884c\u5e76\u8fc7\u6ee4\u6389\u8981\u5220\u9664\u7684\u5217\u3002\u4f7f\u7528 apache commons lang \u5e93\u76f4\u63a5\u79fb\u9664\u5217\u3002\u624b\u52a8\u904d\u5386\u6570\u7ec4\u5e76\u91cd\u65b0\u6784\u9020\u4e00\u4e2a\u65b0\u6570\u7ec4\uff0c\u6392\u9664\u8981\u5220\u9664\u7684\u5217\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/17\/2024111719302022972.jpg\" class=\"aligncenter\" title=\"java\u600e\u4e48\u5220\u9664\u6570\u7ec4\u4e2d\u4e00\u5217\u6570\u636e\u63d2\u56fe\" alt=\"java\u600e\u4e48\u5220\u9664\u6570\u7ec4\u4e2d\u4e00\u5217\u6570\u636e\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u5220\u9664 Java \u6570\u7ec4\u4e2d\u4e00\u5217\u6570\u636e<\/strong><\/p>\n<p>\u8981\u5220\u9664 Java \u6570\u7ec4\u4e2d\u4e00\u5217\u6570\u636e\uff0c\u6709\u51e0\u79cd\u65b9\u6cd5\uff1a<\/p>\n<p><strong>1. \u4f7f\u7528 System.arraycopy()<\/strong><\/p>\n<pre>int[][] arr = { {1, 2, 3}, {4, 5, 6}, {7, 8, 9} };\nint[][] newArr = new int[arr.length - 1][];\n\n\/\/ \u590d\u5236\u6570\u7ec4\u7684\u6bcf\u4e00\u884c\uff0c\u8df3\u8fc7\u8981\u5220\u9664\u7684\u5217\nfor (int i = 0; i &lt; arr.length; i++) {\n    newArr[i] = new int[arr[i].length - 1];\n    System.arraycopy(arr[i], 0, newArr[i], 0, arr[i].length - 1);\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>2. \u4f7f\u7528 Guava \u5e93<\/strong><\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<pre>import com.google.common.collect.ImmutableList;\nimport com.google.common.collect.ImmutableList.Builder;\n\nint[][] arr = { {1, 2, 3}, {4, 5, 6}, {7, 8, 9} };\nBuilder&lt;ImmutableList&lt;ImmutableList&lt;Integer&gt;&gt;&gt; builder = ImmutableList.builder();\n\n\/\/ \u904d\u5386\u6bcf\u4e00\u884c\u5e76\u8fc7\u6ee4\u6389\u8981\u5220\u9664\u7684\u5217\nfor (ImmutableList&lt;Integer&gt; row : ImmutableList.copyOf(arr)) {\n    builder.add(ImmutableList.copyOf(row.subList(0, row.size() - 1)));\n}\n\nImmutableList&lt;ImmutableList&lt;Integer&gt;&gt; newArr = builder.build();<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>3. \u4f7f\u7528 Apache Commons Lang \u5e93<\/strong><\/p>\n<pre>import org.apache.commons.lang3.ArrayUtils;\n\nint[][] arr = { {1, 2, 3}, {4, 5, 6}, {7, 8, 9} };\nint[][] newArr = ArrayUtils.removeColumns(arr, 1);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>4. \u624b\u52a8\u904d\u5386\u5e76\u91cd\u6784\u6570\u7ec4<\/strong><\/p>\n<pre>int[][] arr = { {1, 2, 3}, {4, 5, 6}, {7, 8, 9} };\nint[][] newArr = new int[arr.length][arr[0].length - 1];\n\n\/\/ \u904d\u5386\u6bcf\u4e00\u884c\u5e76\u521b\u5efa\u65b0\u6570\u7ec4\nfor (int i = 0; i &lt; arr.length; i++) {\n    for (int j = 0; j &lt; newArr[i].length; j++) {\n        if (j &lt; arr[i].length - 1) {\n            newArr[i][j] = arr[i][j];\n        }\n    }\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fjava\u600e\u4e48\u5220\u9664\u6570\u7ec4\u4e2d\u4e00\u5217\u6570\u636e\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>\u6709\u56db\u79cd\u65b9\u6cd5\u53ef\u4ee5\u5220\u9664 java \u6570\u7ec4\u4e2d\u7684\u4e00\u5217\u6570\u636e\uff1a\u4f7f\u7528 system.arraycopy() \u590d\u5236\u6570\u7ec4\u7684\u6bcf\u4e00\u884c\uff0c\u8df3\u8fc7\u8981\u5220\u9664\u7684\u5217\u3002\u4f7f\u7528 guava \u5e93\u904d\u5386\u6bcf\u4e00\u884c\u5e76\u8fc7\u6ee4\u6389\u8981\u5220\u9664\u7684\u5217\u3002\u4f7f\u7528 apache commons lang \u5e93\u76f4\u63a5\u79fb\u9664\u5217\u3002\u624b\u52a8\u904d\u5386\u6570\u7ec4\u5e76\u91cd\u65b0\u6784\u9020\u4e00\u4e2a\u65b0\u6570\u7ec4\uff0c\u6392\u9664\u8981\u5220\u9664\u7684\u5217\u3002 \u5982\u4f55\u5220\u9664 Java \u6570\u7ec4\u4e2d\u4e00\u5217\u6570\u636e \u8981\u5220\u9664 Java \u6570\u7ec4\u4e2d\u4e00\u5217\u6570\u636e\uff0c\u6709\u51e0\u79cd\u65b9\u6cd5\uff1a 1. \u4f7f\u7528 System.arraycopy() int[][] arr = { {1, 2, 3}, {4, 5, 6}, {7, 8, 9} }; int[][] newArr = new int[arr.length &#8211; 1][]; \/\/ \u590d\u5236\u6570\u7ec4\u7684\u6bcf\u4e00\u884c\uff0c\u8df3\u8fc7\u8981\u5220\u9664\u7684\u5217 for (int i = 0; i &lt; arr.length; i++) { newArr[i] = [&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-40065","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/40065","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=40065"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/40065\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=40065"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=40065"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=40065"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}