Reverses the order of the given array. - Java Collection Framework

Java examples for Collection Framework:Array Element

Description

Reverses the order of the given array.

Demo Code

public class Main {
  /**/*from  w  ww. j  a  v  a 2  s  . co m*/
   * Reverses the order of the given array.
   * 
   * @param array
   *          the array to reverse
   */
  public static <E> void reverseArray(E[] array) {

    int i = 0;
    int j = array.length - 1;
    E tmp;

    while (j > i) {
      tmp = array[j];
      array[j] = array[i];
      array[i] = tmp;
      j--;
      i++;
    }
  }

}

Related Tutorials