{"id":40309,"date":"2024-11-26T13:35:26","date_gmt":"2024-11-26T05:35:26","guid":{"rendered":"https:\/\/fwq.ai\/blog\/40309\/"},"modified":"2024-11-26T13:35:26","modified_gmt":"2024-11-26T05:35:26","slug":"java%e6%80%8e%e4%b9%88%e5%8f%96%e4%ba%8c%e7%bb%b4%e6%95%b0%e7%bb%84%e7%9a%84%e4%b8%80%e9%83%a8%e5%88%86","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/40309\/","title":{"rendered":"java\u600e\u4e48\u53d6\u4e8c\u7ef4\u6570\u7ec4\u7684\u4e00\u90e8\u5206"},"content":{"rendered":"<blockquote><p>\n  \u4ece java \u4e8c\u7ef4\u6570\u7ec4\u4e2d\u63d0\u53d6\u90e8\u5206\u5185\u5bb9\uff1a\u63d0\u53d6\u7279\u5b9a\u884c\u6216\u5217\uff1a\u4f7f\u7528 arrays.copyofrange() \u63d0\u53d6\u6307\u5b9a\u8303\u56f4\u5185\u7684\u5143\u7d20\u3002\u63d0\u53d6\u6ee1\u8db3\u6761\u4ef6\u7684\u5143\u7d20\uff1a\u4f7f\u7528 stream api \u548c filter() \u7b5b\u9009\u7b26\u5408\u6761\u4ef6\u7684\u5143\u7d20\u3002\u63d0\u53d6\u5b50\u6570\u7ec4\uff1a\u4f7f\u7528 arrays.copyofrange() \u4e24\u6b21\u63d0\u53d6\u6307\u5b9a\u7684\u4e8c\u7ef4\u6570\u7ec4\u90e8\u5206\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/18\/2024111817190110388.jpg\" class=\"aligncenter\" title=\"java\u600e\u4e48\u53d6\u4e8c\u7ef4\u6570\u7ec4\u7684\u4e00\u90e8\u5206\u63d2\u56fe\" alt=\"java\u600e\u4e48\u53d6\u4e8c\u7ef4\u6570\u7ec4\u7684\u4e00\u90e8\u5206\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u4ece Java \u4e8c\u7ef4\u6570\u7ec4\u4e2d\u63d0\u53d6\u90e8\u5206\u5185\u5bb9<\/strong><\/p>\n<p><strong>\u7b80\u4ecb<\/strong><br \/>\u4ece\u4e8c\u7ef4\u6570\u7ec4\u4e2d\u63d0\u53d6\u90e8\u5206\u5185\u5bb9\u662f\u4e00\u9879\u5e38\u89c1\u7684\u4efb\u52a1\uff0c\u4f8b\u5982\uff0c\u60a8\u53ef\u80fd\u9700\u8981\u63d0\u53d6\u8868\u683c\u4e2d\u7684\u7279\u5b9a\u884c\u6216\u5217\uff0c\u6216\u4ec5\u63d0\u53d6\u6ee1\u8db3\u7279\u5b9a\u6761\u4ef6\u7684\u5143\u7d20\u3002Java \u63d0\u4f9b\u4e86\u51e0\u79cd\u65b9\u6cd5\u6765\u5b9e\u73b0\u8fd9\u4e00\u76ee\u6807\u3002<\/p>\n<p><strong>\u63d0\u53d6\u90e8\u5206\u884c\u6216\u5217<\/strong><br \/>\u63d0\u53d6\u7279\u5b9a\u884c\u6216\u5217\u7684\u6700\u7b80\u5355\u65b9\u6cd5\u662f\u4f7f\u7528 Arrays.copyOfRange() \u65b9\u6cd5\u3002\u8be5\u65b9\u6cd5\u63a5\u53d7\u8981\u63d0\u53d6\u7684\u5143\u7d20\u7684\u8d77\u59cb\u548c\u7ed3\u675f\u7d22\u5f15\uff0c\u5e76\u8fd4\u56de\u4e00\u4e2a\u5305\u542b\u6307\u5b9a\u8303\u56f4\u4e2d\u5143\u7d20\u7684\u65b0\u6570\u7ec4\u3002<\/p>\n<pre>int[][] arr = {\n        {1, 2, 3},\n        {4, 5, 6},\n        {7, 8, 9}\n};\n\/\/ \u63d0\u53d6\u7b2c\u4e00\u884c\nint[] firstRow = Arrays.copyOfRange(arr[0], 0, arr[0].length);\n\/\/ \u63d0\u53d6\u7b2c\u4e8c\u5217\nint[] secondColumn = new int[arr.length];\nfor (int i = 0; i &lt; arr.length; i++) {\n    secondColumn[i] = arr[i][1];\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u63d0\u53d6\u6ee1\u8db3\u6761\u4ef6\u7684\u5143\u7d20<\/strong><br \/>\u8981\u63d0\u53d6\u6ee1\u8db3\u7279\u5b9a\u6761\u4ef6\u7684\u5143\u7d20\uff0c\u53ef\u4ee5\u4f7f\u7528 Stream API\u3002Stream API \u63d0\u4f9b\u4e86 filter() \u65b9\u6cd5\uff0c\u8be5\u65b9\u6cd5\u5141\u8bb8\u60a8\u6839\u636e\u4e00\u7ec4\u6761\u4ef6\u7b5b\u9009\u5143\u7d20\u3002<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<pre>int[][] arr = {\n        {1, 2, 3},\n        {4, 5, 6},\n        {7, 8, 9}\n};\n\/\/ \u63d0\u53d6\u6240\u6709\u5927\u4e8e 5 \u7684\u5143\u7d20\nint[] greaterThan5 = Arrays.stream(arr)\n        .flatMapToInt(Arrays::stream)\n        .filter(num -&gt; num &gt; 5)\n        .toArray();<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u63d0\u53d6\u5b50\u6570\u7ec4<\/strong><br \/>\u8981\u63d0\u53d6\u4e8c\u7ef4\u6570\u7ec4\u7684\u4e00\u90e8\u5206\u4f5c\u4e3a\u5b50\u6570\u7ec4\uff0c\u53ef\u4ee5\u4f7f\u7528 Arrays.copyOfRange() \u65b9\u6cd5\u4e24\u6b21\u3002<\/p>\n<pre>int[][] arr = {\n        {1, 2, 3},\n        {4, 5, 6},\n        {7, 8, 9}\n};\n\/\/ \u63d0\u53d6\u524d\u4e24\u884c\nint[][] subArray = Arrays.copyOfRange(arr, 0, 2);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fjava\u600e\u4e48\u53d6\u4e8c\u7ef4\u6570\u7ec4\u7684\u4e00\u90e8\u5206\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>\u4ece java \u4e8c\u7ef4\u6570\u7ec4\u4e2d\u63d0\u53d6\u90e8\u5206\u5185\u5bb9\uff1a\u63d0\u53d6\u7279\u5b9a\u884c\u6216\u5217\uff1a\u4f7f\u7528 arrays.copyofrange() \u63d0\u53d6\u6307\u5b9a\u8303\u56f4\u5185\u7684\u5143\u7d20\u3002\u63d0\u53d6\u6ee1\u8db3\u6761\u4ef6\u7684\u5143\u7d20\uff1a\u4f7f\u7528 stream api \u548c filter() \u7b5b\u9009\u7b26\u5408\u6761\u4ef6\u7684\u5143\u7d20\u3002\u63d0\u53d6\u5b50\u6570\u7ec4\uff1a\u4f7f\u7528 arrays.copyofrange() \u4e24\u6b21\u63d0\u53d6\u6307\u5b9a\u7684\u4e8c\u7ef4\u6570\u7ec4\u90e8\u5206\u3002 \u5982\u4f55\u4ece Java \u4e8c\u7ef4\u6570\u7ec4\u4e2d\u63d0\u53d6\u90e8\u5206\u5185\u5bb9 \u7b80\u4ecb\u4ece\u4e8c\u7ef4\u6570\u7ec4\u4e2d\u63d0\u53d6\u90e8\u5206\u5185\u5bb9\u662f\u4e00\u9879\u5e38\u89c1\u7684\u4efb\u52a1\uff0c\u4f8b\u5982\uff0c\u60a8\u53ef\u80fd\u9700\u8981\u63d0\u53d6\u8868\u683c\u4e2d\u7684\u7279\u5b9a\u884c\u6216\u5217\uff0c\u6216\u4ec5\u63d0\u53d6\u6ee1\u8db3\u7279\u5b9a\u6761\u4ef6\u7684\u5143\u7d20\u3002Java \u63d0\u4f9b\u4e86\u51e0\u79cd\u65b9\u6cd5\u6765\u5b9e\u73b0\u8fd9\u4e00\u76ee\u6807\u3002 \u63d0\u53d6\u90e8\u5206\u884c\u6216\u5217\u63d0\u53d6\u7279\u5b9a\u884c\u6216\u5217\u7684\u6700\u7b80\u5355\u65b9\u6cd5\u662f\u4f7f\u7528 Arrays.copyOfRange() \u65b9\u6cd5\u3002\u8be5\u65b9\u6cd5\u63a5\u53d7\u8981\u63d0\u53d6\u7684\u5143\u7d20\u7684\u8d77\u59cb\u548c\u7ed3\u675f\u7d22\u5f15\uff0c\u5e76\u8fd4\u56de\u4e00\u4e2a\u5305\u542b\u6307\u5b9a\u8303\u56f4\u4e2d\u5143\u7d20\u7684\u65b0\u6570\u7ec4\u3002 int[][] arr = { {1, 2, 3}, {4, 5, 6}, {7, 8, 9} }; \/\/ \u63d0\u53d6\u7b2c\u4e00\u884c int[] firstRow = Arrays.copyOfRange(arr[0], 0, arr[0].length); \/\/ \u63d0\u53d6\u7b2c\u4e8c\u5217 int[] secondColumn = new int[arr.length]; for (int i = 0; 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-40309","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/40309","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=40309"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/40309\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=40309"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=40309"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=40309"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}