Reverse the order of the given boolean type value array in Java
Description
The following code shows how to reverse the order of the given boolean type value array.
Example
// w ww.j a v a 2 s .c om
import java.util.Arrays;
public class Main {
public static void main(String[] argv){
boolean[] data = new boolean[]{true,false,true};
System.out.println(Arrays.toString(data));
reverse(data);
System.out.println(Arrays.toString(data));
}
public static void reverse(boolean[] array) {
if (array == null) {
return;
}
int i = 0;
int j = array.length - 1;
boolean 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 »