{"id":65617,"date":"2025-05-03T12:55:20","date_gmt":"2025-05-03T04:55:20","guid":{"rendered":"https:\/\/fwq.ai\/blog\/65617\/"},"modified":"2025-05-03T12:55:20","modified_gmt":"2025-05-03T04:55:20","slug":"java%e6%95%b0%e7%bb%84%e9%80%86%e5%ba%8f%e6%80%8e%e4%b9%88%e5%81%9a-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/65617\/","title":{"rendered":"java\u6570\u7ec4\u9006\u5e8f\u600e\u4e48\u505a"},"content":{"rendered":"<blockquote><p>\n  java\u6570\u7ec4\u9006\u5e8f\u65b9\u6cd5\u6709\u56db\u79cd\uff1a\u76f4\u63a5\u904d\u5386\u3001\u9012\u5f52\u3001\u4f7f\u7528collections.reverse()\u3001\u4f7f\u7528stream api\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/13\/2024111305363255023.jpg\" class=\"aligncenter\" title=\"java\u6570\u7ec4\u9006\u5e8f\u600e\u4e48\u505a\u63d2\u56fe\" alt=\"java\u6570\u7ec4\u9006\u5e8f\u600e\u4e48\u505a\u63d2\u56fe\" \/><\/p>\n<p><strong>Java\u6570\u7ec4\u9006\u5e8f\u7684\u65b9\u6cd5<\/strong><\/p>\n<p>\u9006\u5e8fJava\u6570\u7ec4\u662f\u4e00\u79cd\u5e38\u89c1\u64cd\u4f5c\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u65b9\u6cd5\u5b9e\u73b0\uff1a<\/p>\n<p><strong>1. \u76f4\u63a5\u904d\u5386<\/strong><\/p>\n<pre>\/\/ \u6570\u7ec4a\nint[] a = {1, 2, 3, 4, 5};\n\nfor (int i = 0; i &lt; a.length \/ 2; i++) {\n    int temp = a[i];\n    a[i] = a[a.length - i - 1];\n    a[a.length - i - 1] = temp;\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>2. \u9012\u5f52<\/strong><\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<pre>\/\/ \u6570\u7ec4a\nint[] a = {1, 2, 3, 4, 5};\n\npublic static void reverseArray(int[] arr, int left, int right) {\n    if (left &gt;= right) {\n        return;\n    }\n    int temp = arr[left];\n    arr[left] = arr[right];\n    arr[right] = temp;\n    reverseArray(arr, left + 1, right - 1);\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>3. \u4f7f\u7528Collections.reverse()<\/strong><\/p>\n<pre>import java.util.Collections;\n\n\/\/ \u6570\u7ec4a\nint[] a = {1, 2, 3, 4, 5};\n\nCollections.reverse(Arrays.asList(a));<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>4. \u4f7f\u7528Stream API<\/strong><\/p>\n<pre>import java.util.Arrays;\nimport java.util.List;\n\n\/\/ \u6570\u7ec4a\nint[] a = {1, 2, 3, 4, 5};\n\nList&lt;Integer&gt; list = Arrays.stream(a).boxed().toList();\nCollections.reverse(list);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fjava\u6570\u7ec4\u9006\u5e8f\u600e\u4e48\u505a\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>java\u6570\u7ec4\u9006\u5e8f\u65b9\u6cd5\u6709\u56db\u79cd\uff1a\u76f4\u63a5\u904d\u5386\u3001\u9012\u5f52\u3001\u4f7f\u7528collections.reverse()\u3001\u4f7f\u7528stream api\u3002 Java\u6570\u7ec4\u9006\u5e8f\u7684\u65b9\u6cd5 \u9006\u5e8fJava\u6570\u7ec4\u662f\u4e00\u79cd\u5e38\u89c1\u64cd\u4f5c\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u65b9\u6cd5\u5b9e\u73b0\uff1a 1. \u76f4\u63a5\u904d\u5386 \/\/ \u6570\u7ec4a int[] a = {1, 2, 3, 4, 5}; for (int i = 0; i &lt; a.length \/ 2; i++) { int temp = a[i]; a[i] = a[a.length &#8211; i &#8211; 1]; a[a.length &#8211; i &#8211; 1] = temp; } \u767b\u5f55\u540e\u590d\u5236 2. \u9012\u5f52 \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b \/\/ \u6570\u7ec4a int[] a [&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-65617","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/65617","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=65617"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/65617\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=65617"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=65617"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=65617"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}