Java Array Swap swap(final int[] array, final int pos1, final int pos2)

Here you can find the source of swap(final int[] array, final int pos1, final int pos2)

Description

Swaps two elements in the array.

License

Open Source License

Parameter

Parameter Description
array array with element
pos1 index of first element
pos2 index of second element

Declaration

static void swap(final int[] array, final int pos1, final int pos2) 

Method Source Code

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

public class Main {
    /**// w  w w .  j a v a 2 s.c  o  m
     * Swaps two elements in the array.
     *
     * @param array array with element
     * @param pos1 index of first element
     * @param pos2 index of second element
     */
    static void swap(final int[] array, final int pos1, final int pos2) {
        final int temp = array[pos1];
        array[pos1] = array[pos2];
        array[pos2] = temp;
    }
}

Related

  1. swap(final byte[] src)
  2. swap(final float[] pVertices, final int pVertexStride, final int pVertexIndexA, final int pVertexIndexB)
  3. swap(final int a[], final int i, final int j)
  4. swap(final int[] array, final int i, final int j)
  5. swap(final int[] array, final int indexA, final int indexB)
  6. swap(final Object[] array, final int i, final int j)
  7. swap(final Object[] array, int offset1, int offset2)
  8. swap(final Object[] array, int pos)
  9. swap(final Object[] data, final int i, final int j)