Java Array Swap swap(T[] a, int i1, int i2)

Here you can find the source of swap(T[] a, int i1, int i2)

Description

Swaps objects at specified index in array

License

Open Source License

Parameter

Parameter Description
T Type that implements Comparable
a Array of objects that implement comparable
i1 index of object to be switched
i2 second index of object to be switched

Declaration

private static <T extends Comparable> void swap(T[] a, int i1, int i2) 

Method Source Code

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

public class Main {
    /**//from w w w.j  a  v a  2  s  . c o m
     * Swaps objects at specified index in array
     *
     * @param <T> Type that implements Comparable
     * @param a   Array of objects that implement comparable
     * @param i1  index of object to be switched
     * @param i2  second index of object to be switched
     */
    private static <T extends Comparable> void swap(T[] a, int i1, int i2) {
        T temp = a[i1];
        a[i1] = a[i2];
        a[i2] = temp;
    }
}

Related

  1. swap(short x[], int a, int b)
  2. swap(short x[], int[] y, int a, int b)
  3. swap(short x[], T[] a2, int a, int b)
  4. swap(short[] array, int indexA, int indexB)
  5. swap(String a[], int i, int j)
  6. swap(T[] a, int idx1, int idx2)
  7. swap(T[] arr, int a, int b)
  8. swap(T[] arr, int i, int j)
  9. swap(T[] arr, int index1, int index2)