{"id":65354,"date":"2025-05-03T16:35:44","date_gmt":"2025-05-03T08:35:44","guid":{"rendered":"https:\/\/fwq.ai\/blog\/65354\/"},"modified":"2025-05-03T16:35:44","modified_gmt":"2025-05-03T08:35:44","slug":"java%e6%80%8e%e4%b9%88%e5%80%92%e5%ba%8f%e6%95%b0%e7%bb%84-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/65354\/","title":{"rendered":"java\u600e\u4e48\u5012\u5e8f\u6570\u7ec4"},"content":{"rendered":"<blockquote><p>\n  java\u4e2d\u5012\u5e8f\u6570\u7ec4\u6709\u4e24\u79cd\u65b9\u6cd5\uff1a\u4f7f\u7528collections.reverse()\u65b9\u6cd5\u624b\u52a8\u904d\u5386\u6570\u7ec4\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/12\/2024111221394481840.jpg\" class=\"aligncenter\" title=\"java\u600e\u4e48\u5012\u5e8f\u6570\u7ec4\u63d2\u56fe\" alt=\"java\u600e\u4e48\u5012\u5e8f\u6570\u7ec4\u63d2\u56fe\" \/><\/p>\n<p><strong>Java\u4e2d\u5012\u5e8f\u6570\u7ec4<\/strong><\/p>\n<p>\u5728Java\u4e2d\u5012\u5e8f\u6570\u7ec4\u6709\u4e24\u79cd\u4e3b\u8981\u65b9\u6cd5\uff1a<\/p>\n<p><strong>1. \u4f7f\u7528Collections.reverse()\u65b9\u6cd5<\/strong><\/p>\n<pre>int[] arr = {1, 2, 3, 4, 5};\nCollections.reverse(Arrays.asList(arr));<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>2. \u624b\u52a8\u904d\u5386\u6570\u7ec4<\/strong><\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<pre>int[] arr = {1, 2, 3, 4, 5};\nint i = 0;\nint j = arr.length - 1;\nwhile (i &lt; j) {\n    int temp = arr[i];\n    arr[i] = arr[j];\n    arr[j] = temp;\n    i++;\n    j--;\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u793a\u4f8b\u4ee3\u7801\uff1a<\/strong><\/p>\n<pre>int[] myArray = {5, 2, 8, 1, 4};\n\n\/\/ \u65b9\u6cd5 1\uff1a\u4f7f\u7528Collections.reverse()\nCollections.reverse(Arrays.asList(myArray));\nSystem.out.println(Arrays.toString(myArray)); \/\/ \u8f93\u51fa\uff1a[4, 1, 8, 2, 5]\n\n\/\/ \u65b9\u6cd5 2\uff1a\u624b\u52a8\u904d\u5386\u6570\u7ec4\nint i = 0;\nint j = myArray.length - 1;\nwhile (i &lt; j) {\n    int temp = myArray[i];\n    myArray[i] = myArray[j];\n    myArray[j] = temp;\n    i++;\n    j--;\n}\nSystem.out.println(Arrays.toString(myArray)); \/\/ \u8f93\u51fa\uff1a[4, 1, 8, 2, 5]<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fjava\u600e\u4e48\u5012\u5e8f\u6570\u7ec4\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\u4e2d\u5012\u5e8f\u6570\u7ec4\u6709\u4e24\u79cd\u65b9\u6cd5\uff1a\u4f7f\u7528collections.reverse()\u65b9\u6cd5\u624b\u52a8\u904d\u5386\u6570\u7ec4 Java\u4e2d\u5012\u5e8f\u6570\u7ec4 \u5728Java\u4e2d\u5012\u5e8f\u6570\u7ec4\u6709\u4e24\u79cd\u4e3b\u8981\u65b9\u6cd5\uff1a 1. \u4f7f\u7528Collections.reverse()\u65b9\u6cd5 int[] arr = {1, 2, 3, 4, 5}; Collections.reverse(Arrays.asList(arr)); \u767b\u5f55\u540e\u590d\u5236 2. \u624b\u52a8\u904d\u5386\u6570\u7ec4 \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b int[] arr = {1, 2, 3, 4, 5}; int i = 0; int j = arr.length &#8211; 1; while (i &lt; j) { int temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; i++; j&#8211;; } \u767b\u5f55\u540e\u590d\u5236 [&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-65354","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/65354","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=65354"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/65354\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=65354"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=65354"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=65354"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}