Skip to content

Instantly share code, notes, and snippets.

@jweinst1
Created September 1, 2015 07:29
Show Gist options
  • Select an option

  • Save jweinst1/fb4f81ab19d673fa0b31 to your computer and use it in GitHub Desktop.

Select an option

Save jweinst1/fb4f81ab19d673fa0b31 to your computer and use it in GitHub Desktop.
Returns a Reversed Version of an Array in Java
import java.util.Arrays;
class Main {
public static void main(String[] args) {
System.out.println(Arrays.toString(reversed(lst)));
}
static int[] lst = {1, 2, 3, 4, 5};
static int[] reversed(int[] x){
int size = x.length;
int[] xcopy = new int[size];
int counter = size - 1;
int revcount = 0;
while (counter >= 0) {
xcopy[revcount] = x[counter];
counter -= 1;
revcount ++;
}
return xcopy;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment