Created
August 25, 2021 01:24
-
-
Save daanta-real/f3342166b2423c94d0465118e31ce1d6 to your computer and use it in GitHub Desktop.
Reverse a single dimension array's elements (all types)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static Object array_reverse(Object[] arr) { | |
for(int i = 0; i < arr.length / 2; i++) { | |
int start = i; | |
int end = arr.length - 1 - i; | |
Object temp = arr[start]; | |
arr[start] = arr[end]; | |
arr[end] = temp; | |
} | |
return arr; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment