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

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

Description

Swaps the two specified elements in the specified array.

License

Apache License

Declaration

private static void swap(Object[] arr, int i, int j) 

Method Source Code

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

import java.util.List;

public class Main {
    /**/*from  ww  w  .  jav a 2 s  . com*/
     * Swaps the two specified elements in the specified array.
     */
    private static void swap(Object[] arr, int i, int j) {
        Object tmp = arr[i];
        arr[i] = arr[j];
        arr[j] = tmp;
    }

    @SuppressWarnings({ "rawtypes", "unchecked" })
    public static void swap(List<?> list, int i, int j) {
        // instead of using a raw type here, it's possible to capture
        // the wildcard but it will require a call to a supplementary
        // private method
        final List l = list;
        l.set(i, l.set(j, l.get(i)));
    }
}

Related

  1. swap(long[] a, int i, int change)
  2. swap(long[] keys, double[] values, int i, int j)
  3. swap(Object aobj[], int i, int j, int k)
  4. swap(Object[] arr, int a, int b)
  5. swap(Object[] arr, int i, int j)
  6. swap(Object[] array)
  7. swap(Object[] array, int a, int b)
  8. swap(Object[] x, int a, int b)
  9. swap(short x[], int a, int b)