reverse integer array in java code example
Example 1: reverse array in java
int length = array.length;
for(int i=0;i<length/2;i++) {
int swap = array[i];
array[i] = array[length-i-1];
array[length-i-1] = swap;
}
or
Collections.reverse(Arrays.asList(array));
Example 2: reverse a integer in java
while(num != 0)
{
int digit = num % 10;
reversed = reversed * 10 + digit;
num /= 10;
}
Example 3: reverse array java
// reverse array
for(int i=intArray.length-1;i>=0;i--)
System.out.print(intArray[i] + " ");