Reverse Array Order Reverse Array Order arrays arrays

Reverse Array Order


If it's an Object array, then Collections.reverse(Arrays.asList(array)) will do the job with constant memory and linear time -- no temporary array required.


Use a single temp element.

int array[SIZE];int temp;for (int i = 0; i < SIZE/2; i++)  {     temp = array[i];     array[i] = array[SIZE-1 - i];     array[SIZE-1 - i] = temp;  }


You don't need to use a temporary array; just step through the array from the beginning to half-way through, swapping the element at i for the element at array.length-i-1. Be sure the handle the middle element correctly (not hard to do, but do make sure.)