Reverses the order of an array(byte, long, int)
import java.util.Arrays;
public class Main {
public static void reverse(byte[] array) {
if (array == null) {
return;
}
int i = 0;
int j = array.length - 1;
byte tmp;
while (j > i) {
tmp = array[j];
array[j] = array[i];
array[i] = tmp;
j--;
i++;
}
}
public static void main(String[] args) {
byte[] b1 = new byte[] { 3, 2, 5, 4, 1 };
for (byte b : b1) {
System.out.println(b);
}
reverse(b1);
for (byte b : b1) {
System.out.println(b);
}
}
}
Output:
3
2
5
4
1
1
4
5
2
3
Reverses the order of the given long type value array.
public class Main {
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++;
}
}
}
Reverses the order of the given int type value array.
public class Main {
public static void reverse(int[] array) {
if (array == null) {
return;
}
int i = 0;
int j = array.length - 1;
int tmp;
while (j > i) {
tmp = array[j];
array[j] = array[i];
array[i] = tmp;
j--;
i++;
}
}
}
Reverses the order of the given short type value array.
public class Main {
public static void reverse(short[] array) {
if (array == null) {
return;
}
int i = 0;
int j = array.length - 1;
short tmp;
while (j > i) {
tmp = array[j];
array[j] = array[i];
array[i] = tmp;
j--;
i++;
}
}
}
Reverses the order of the given char type value array.
public class Main {
public static void reverse(char[] array) {
if (array == null) {
return;
}
int i = 0;
int j = array.length - 1;
char tmp;
while (j > i) {
tmp = array[j];
array[j] = array[i];
array[i] = tmp;
j--;
i++;
}
}
}
Reverses the order of the given byte type array.
public class Main {
public static void reverse(byte[] array) {
if (array == null) {
return;
}
int i = 0;
int j = array.length - 1;
byte tmp;
while (j > i) {
tmp = array[j];
array[j] = array[i];
array[i] = tmp;
j--;
i++;
}
}
}
Reverses the order of the given double value type array.
public class Main {
public static void reverse(double[] array) {
if (array == null) {
return;
}
int i = 0;
int j = array.length - 1;
double tmp;
while (j > i) {
tmp = array[j];
array[j] = array[i];
array[i] = tmp;
j--;
i++;
}
}
}
Reverses the order of the given float type value array.
public class Main {
public static void reverse(float[] array) {
if (array == null) {
return;
}
int i = 0;
int j = array.length - 1;
float tmp;
while (j > i) {
tmp = array[j];
array[j] = array[i];
array[i] = tmp;
j--;
i++;
}
}
}
Reverses the order of the given boolean type value array.
public class Main {
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++;
}
}
}
Home
Java Book
Runnable examples
Java Book
Runnable examples
Data Type Array:
- Append item to array
- Append an object to an array.
- Append one array to another
- Clone Array
- Clones two dimensional float array
- Compare two arrays by reference
- Compare Two byte Arrays
- Compare Two boolean Arrays
- Compare Two char Arrays
- Compare Two double Arrays
- Compare Two float Arrays
- Compare Two int Arrays
- Compare Two long Arrays
- Compare two object arrays
- Compare Two short Arrays
- Compare two two-dimensional array
- Concatenate arrays
- Convert array to set
- Convert string array to string
- Convert string array to List
- Convert multi-dimensional array to string
- Convert an array to a Map
- Copy array
- Copy Elements from One Array to Another
- Copy and add an array at the end of the new array
- Extend an array with additional extra space
- Extend to Double the size of an array
- Fill boolean, byte, char,short, int, long, float array
- Get array upperbound
- Get the number of dimensions
- Insert an Element into a Sorted Array
- Insert the specified element at the specified position in the array
- Insert source array in the target array at offset
- Maximum value in an array
- Minimum value in an array.
- Merge two arrays
- Remove duplicate element from array
- Remove the element at the specified position from the specified array.
- Reverses the order of an array(byte, long, int)
- Search an element in an array and return the index and last index
- Binary Search on an Array
- Shift all elements right by one
- Shift all elements left by one
- Shuffle an array
- Sort byte(char,double, float, int) Array
- Sort char array
- Sort int Array
- Sort long Array
- Sort short Array
- Sort string type array in case insensitive order and case sensitive order
- Sort an Array in Descending (Reverse) Order
- Start with one array
- Subarray from array that starts at offset