Reverse the order of the given long type value array in Java
Description
The following code shows how to reverse the order of the given long type value array.
Example
/*from w w w . j a v a 2s. com*/
import java.util.Arrays;
public class Main {
public static void main(String[] argv){
long[] data = new long[]{1,2,3,4,5};
System.out.println(Arrays.toString(data));
reverse(data);
System.out.println(Arrays.toString(data));
}
public static void reverse(long[] array) {
if (array == null) {
return;
}
int i = 0;
int j = array.length - 1;
long tmp;
while (j > i) {
tmp = array[j];
array[j] = array[i];
array[i] = tmp;
j--;
i++;
}
}
}
The code above generates the following result.
Home »
Java Tutorial »
Java Data Type »
Java Tutorial »
Java Data Type »