Java Array Swap swap(final Object[] data, final int i, final int j)

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

Description

Exchanges the elements at the two provided indices in the given array.

License

Open Source License

Parameter

Parameter Description
data The data in which to exchange elements.
i The first element to exchange.
j The second element to exchange.

Declaration

public static void swap(final Object[] data, final int i, final int j) 

Method Source Code

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

public class Main {
    /**/*from  ww  w. j a  v a 2  s  .c  o m*/
     * Exchanges the elements at the two provided indices in the given array.
     * 
     * @param data The data in which to exchange elements.
     * @param i The first element to exchange.
     * @param j The second element to exchange.
     */
    public static void swap(final Object[] data, final int i, final int j) {
        /* Assume the indices are within the bounds of the array. */
        final Object tmp = data[i];
        data[i] = data[j];
        data[j] = tmp;
    }
}

Related

  1. swap(final int[] array, final int indexA, final int indexB)
  2. swap(final int[] array, final int pos1, final int pos2)
  3. swap(final Object[] array, final int i, final int j)
  4. swap(final Object[] array, int offset1, int offset2)
  5. swap(final Object[] array, int pos)
  6. swap(final Object[] values, final int firstPosition, final int secondPosition)
  7. swap(final String a[], final int i, final int j)
  8. swap(final T[] arr, final int i, final int j)
  9. swap(final T[] arr, final int i, final int j)