Here you can find the source of swap(Object[] array)
Parameter | Description |
---|---|
array | the Object array to be reversed |
public static void swap(Object[] array)
//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; } } }