Java Array Swap swap(int[] a, int i, int j)

Here you can find the source of swap(int[] a, int i, int j)

Description

Swap ith element in a with jth element.

License

Open Source License

Declaration

public static void swap(int[] a, int i, int j) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /** Swap ith element in a with jth element. */
    public static void swap(int[] a, int i, int j) {
        int temp = a[i];
        a[i] = a[j];/*ww  w  . j  a v a2 s .c  o m*/
        a[j] = temp;
    }

    /** Swap ith element in a with jth element. */
    public static <T> void swap(T[] a, int i, int j) {
        T temp = a[i];
        a[i] = a[j];
        a[j] = temp;
    }

    private static void swap(Object i, Object j) {
        Object temp = i;
        i = j;
        j = temp;
        // i.setValue() would have worked.
    }
}

Related

  1. swap(int arrs[], int i, int j)
  2. swap(int i, int j, Integer[] unsorted)
  3. swap(int i, int j, String[] index)
  4. swap(int keys[], int values[], int a, int b)
  5. swap(int[] a, int first, int second)
  6. swap(int[] arr, int a, int b)
  7. swap(int[] arr, int a, int b)
  8. swap(int[] arr, int a, int b, int c, int d, int key)
  9. swap(int[] arr, int i, int j)