Java Array Swap swap(boolean[] array, int i1, int i2)

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

Description

Swaps two elements of a vector

License

Open Source License

Parameter

Parameter Description
array te vector
i1 the index of the first element to be swapped
i2 the index of the second element to be swapped

Declaration

public static void swap(boolean[] array, int i1, int i2) 

Method Source Code

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

public class Main {
    /**//from w  w  w .  j ava 2 s . co m
     * Swaps two elements of a vector
     * @param array te vector
     * @param i1 the index of the first element to be swapped
     * @param i2 the index of the second element to be swapped
     */
    public static void swap(int[] array, int i1, int i2) {
        int temp = array[i1];
        array[i1] = array[i2];
        array[i2] = temp;
    }

    /**
     * Swaps two elements of a vector
     * @param array te vector
     * @param i1 the index of the first element to be swapped
     * @param i2 the index of the second element to be swapped
     */
    public static void swap(boolean[] array, int i1, int i2) {
        boolean temp = array[i1];
        array[i1] = array[i2];
        array[i2] = temp;
    }

    /**
     * Swaps two elements of a vector
     * @param array te vector
     * @param i1 the index of the first element to be swapped
     * @param i2 the index of the second element to be swapped
     */
    public static void swap(double[] array, int i1, int i2) {
        double temp = array[i1];
        array[i1] = array[i2];
        array[i2] = temp;
    }

    /**
     * Swaps two elements of a vector
     * @param array te vector
     * @param i1 the index of the first element to be swapped
     * @param i2 the index of the second element to be swapped
     */
    public static void swap(char[] array, int i1, int i2) {
        char temp = array[i1];
        array[i1] = array[i2];
        array[i2] = temp;
    }
}

Related

  1. swap(byte size, byte[] target, short targetOffset, byte[] a, short aOffset)
  2. swap(byte[] b1)
  3. swap(byte[] buffer, int i, int j)
  4. swap(byte[] bytes)