Java Array Swap swap(int[] array, int x, int y)

Here you can find the source of swap(int[] array, int x, int y)

Description

Swaps the given indices x with y in the array.

License

Apache License

Declaration

public static void swap(int[] array, int x, int y) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    /**//from   www.j  a  v  a 2 s  .c o m
     * Swaps the given indices x with y in the array.
     */
    public static void swap(int[] array, int x, int y) {
        int tmpIndex = array[x];
        array[x] = array[y];
        array[y] = tmpIndex;
    }

    /**
     * Swaps the given indices x with y in the array.
     */
    public static void swap(long[] array, int x, int y) {
        long tmpIndex = array[x];
        array[x] = array[y];
        array[y] = tmpIndex;
    }

    /**
     * Swaps the given indices x with y in the array.
     */
    public static void swap(double[] array, int x, int y) {
        double tmpIndex = array[x];
        array[x] = array[y];
        array[y] = tmpIndex;
    }

    /**
     * Swaps the given indices x with y in the array.
     */
    public static void swap(boolean[] array, int x, int y) {
        boolean tmpIndex = array[x];
        array[x] = array[y];
        array[y] = tmpIndex;
    }

    /**
     * Swaps the given indices x with y in the array.
     */
    public static <T> void swap(T[] array, int x, int y) {
        T tmpIndex = array[x];
        array[x] = array[y];
        array[y] = tmpIndex;
    }
}

Related

  1. swap(int[] arr, int i, int j)
  2. swap(int[] array)
  3. swap(int[] array, int i, int j)
  4. swap(int[] array, int idx1, int idx2)
  5. swap(int[] array, int index0, int index1)
  6. swap(int[] inArray, int index1, int index2)
  7. swap(int[] integers, int positionX, int positionY)
  8. swap(int[] list, int i, int j)
  9. swap(long[] a, int i, int change)