Java Array Swap swap(final Object[] array, int pos)

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

Description

swap

License

Open Source License

Declaration

public static void swap(final Object[] array, int pos) 

Method Source Code

//package com.java2s;
/*//www.j  a  v a  2s  .  co m
 * This program is free software: you can redistribute it and/or modify it 
 * under the terms of the GNU General Public License as published by 
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 */

public class Main {
    public static void swap(final Object[] array, int pos) {
        swap(array, pos, pos + 1);
    }

    public static void swap(final Object[] array, int pos, boolean forward) {
        int pos2 = (forward) ? pos + 1 : pos - 1;
        swap(array, pos, pos2);
    }

    public static void swap(final Object[] array, int pos, int pos2) {
        if (pos == pos2)
            return;

        Object temp = array[pos];
        array[pos] = array[pos2];
        array[pos2] = temp;
    }

    public static void swap(final int[] array, int pos, int pos2) {
        if (pos == pos2)
            return;

        int temp = array[pos];
        array[pos] = array[pos2];
        array[pos2] = temp;
    }
}

Related

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