Java Array Swap swap(T[] array, int i, int len)

Here you can find the source of swap(T[] array, int i, int len)

Description

swap

License

Open Source License

Declaration

private static <T> void swap(T[] array, int i, int len) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2010 Oobium, Inc./*from   w ww  .j av a 2s.c  o  m*/
 * 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:
 *     Jeremy Dowdall <jeremy@oobium.com> - initial API and implementation
 ******************************************************************************/

import java.util.List;

public class Main {
    private static <T> void swap(T[] array, int i, int len) {
        T tmp = array[i];
        array[i] = array[len - i - 1];
        array[len - i - 1] = tmp;
    }

    private static <T> void swap(List<T> list, int i, int len) {
        T tmp = list.get(i);
        list.set(i, list.get(len - i - 1));
        list.set(len - i - 1, tmp);
    }
}

Related

  1. swap(T[] arr, int i, int j)
  2. swap(T[] arr, int index1, int index2)
  3. swap(T[] arr, int pos1, int pos2)
  4. swap(T[] array, int a, int b)
  5. swap(T[] array, int first_idx, int last_idx)
  6. swap(T[] array, int indexOne, int indexTwo)
  7. swap(T[] data, int a, int b)
  8. swap(T[] elements, int i, int j)
  9. swap(T[] ts, int i, int j)