Java Array Swap swap(Object[] array)

Here you can find the source of swap(Object[] array)

Description

Reverse the elements in the array.

License

Open Source License

Parameter

Parameter Description
array the Object array to be reversed

Declaration

public static void swap(Object[] array) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2003, 2011 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:/*from www. j a  v  a 2s .c o m*/
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/

public class Main {
    /**
     *  Reverse the elements in the array.
     *  
     * @param      array   the Object array to be reversed
     */
    public static void swap(Object[] array) {
        int start = 0;
        int end = array.length - 1;
        while (start < end) {
            Object temp = array[start];
            array[start++] = array[end];
            array[end--] = temp;
        }
    }
}

Related

  1. swap(long[] keys, double[] values, int i, int j)
  2. swap(Object aobj[], int i, int j, int k)
  3. swap(Object[] arr, int a, int b)
  4. swap(Object[] arr, int i, int j)
  5. swap(Object[] arr, int i, int j)
  6. swap(Object[] array, int a, int b)
  7. swap(Object[] x, int a, int b)
  8. swap(short x[], int a, int b)
  9. swap(short x[], int[] y, int a, int b)