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

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

Description

Swap two positions.

License

Open Source License

Declaration

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

Method Source Code

//package com.java2s;

public class Main {
    /**//from  ww  w  . ja va2s  .  c o m
     * Swap two positions.
     */
    public static void swap(int arr[], int i, int j) {
        int a = arr[i];
        arr[i] = arr[j];
        arr[j] = a;
    }

    /**
     * Swap two positions.
     */
    public static void swap(float arr[], int i, int j) {
        float a = arr[i];
        arr[i] = arr[j];
        arr[j] = a;
    }

    /**
     * Swap two positions.
     */
    public static void swap(double arr[], int i, int j) {
        double a;
        a = arr[i];
        arr[i] = arr[j];
        arr[j] = a;
    }

    /**
     * Swap two positions.
     */
    public static void swap(Object arr[], int i, int j) {
        Object a;
        a = arr[i];
        arr[i] = arr[j];
        arr[j] = a;
    }
}

Related

  1. swap(final Object[] data, final int i, final int j)
  2. swap(final Object[] values, final int firstPosition, final int secondPosition)
  3. swap(final String a[], final int i, final int j)
  4. swap(final T[] arr, final int i, final int j)
  5. swap(final T[] arr, final int i, final int j)
  6. swap(int array[], int first, int last)
  7. swap(int arrs[], int i, int j)
  8. swap(int i, int j, Integer[] unsorted)
  9. swap(int i, int j, String[] index)