Java Array Swap swapAll(final Object[] array)

Here you can find the source of swapAll(final Object[] array)

Description

swap All

License

Open Source License

Declaration

public static void swapAll(final Object[] array) 

Method Source Code

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

public class Main {
    public static void swapAll(final Object[] array) {
        Object tmp;//from  w  ww  .  j av  a2  s  .c  o m

        for (int i = 0, j = array.length - 1; i < j; i++, j--) {
            tmp = array[i];
            array[i] = array[j];
            array[j] = tmp;
        }
    }

    public static void swapAll(final boolean[] array) {
        boolean tmp;

        for (int i = 0, j = array.length - 1; i < j; i++, j--) {
            tmp = array[i];
            array[i] = array[j];
            array[j] = tmp;
        }
    }

    public static void swapAll(final byte[] array) {
        byte tmp;

        for (int i = 0, j = array.length - 1; i < j; i++, j--) {
            tmp = array[i];
            array[i] = array[j];
            array[j] = tmp;
        }
    }

    public static void swapAll(final char[] array) {
        char tmp;

        for (int i = 0, j = array.length - 1; i < j; i++, j--) {
            tmp = array[i];
            array[i] = array[j];
            array[j] = tmp;
        }
    }

    public static void swapAll(final short[] array) {
        short tmp;

        for (int i = 0, j = array.length - 1; i < j; i++, j--) {
            tmp = array[i];
            array[i] = array[j];
            array[j] = tmp;
        }
    }

    public static void swapAll(final int[] array) {
        int tmp;

        for (int i = 0, j = array.length - 1; i < j; i++, j--) {
            tmp = array[i];
            array[i] = array[j];
            array[j] = tmp;
        }
    }

    public static void swapAll(final long[] array) {
        long tmp;

        for (int i = 0, j = array.length - 1; i < j; i++, j--) {
            tmp = array[i];
            array[i] = array[j];
            array[j] = tmp;
        }
    }

    public static void swapAll(final float[] array) {
        float tmp;

        for (int i = 0, j = array.length - 1; i < j; i++, j--) {
            tmp = array[i];
            array[i] = array[j];
            array[j] = tmp;
        }
    }

    public static void swapAll(final double[] array) {
        double tmp;

        for (int i = 0, j = array.length - 1; i < j; i++, j--) {
            tmp = array[i];
            array[i] = array[j];
            array[j] = tmp;
        }
    }

    public static void swapAll(final Object[] array, final int off, final int len) {
        final int last = off + len - 1;
        Object tmp;

        for (int i = off, j = last; i < j; i++, j--) {
            tmp = array[i];
            array[i] = array[j];
            array[j] = tmp;
        }
    }

    public static void swapAll(final boolean[] array, final int off, final int len) {
        final int last = off + len - 1;
        boolean tmp;

        for (int i = off, j = last; i < j; i++, j--) {
            tmp = array[i];
            array[i] = array[j];
            array[j] = tmp;
        }
    }

    public static void swapAll(final byte[] array, final int off, final int len) {
        final int last = off + len - 1;
        byte tmp;

        for (int i = off, j = last; i < j; i++, j--) {
            tmp = array[i];
            array[i] = array[j];
            array[j] = tmp;
        }
    }

    public static void swapAll(final char[] array, final int off, final int len) {
        final int last = off + len - 1;
        char tmp;

        for (int i = off, j = last; i < j; i++, j--) {
            tmp = array[i];
            array[i] = array[j];
            array[j] = tmp;
        }
    }

    public static void swapAll(final short[] array, final int off, final int len) {
        final int last = off + len - 1;
        short tmp;

        for (int i = off, j = last; i < j; i++, j--) {
            tmp = array[i];
            array[i] = array[j];
            array[j] = tmp;
        }
    }

    public static void swapAll(final int[] array, final int off, final int len) {
        final int last = off + len - 1;
        int tmp;

        for (int i = off, j = last; i < j; i++, j--) {
            tmp = array[i];
            array[i] = array[j];
            array[j] = tmp;
        }
    }

    public static void swapAll(final long[] array, final int off, final int len) {
        final int last = off + len - 1;
        long tmp;

        for (int i = off, j = last; i < j; i++, j--) {
            tmp = array[i];
            array[i] = array[j];
            array[j] = tmp;
        }
    }

    public static void swapAll(final float[] array, final int off, final int len) {
        final int last = off + len - 1;
        float tmp;

        for (int i = off, j = last; i < j; i++, j--) {
            tmp = array[i];
            array[i] = array[j];
            array[j] = tmp;
        }
    }

    public static void swapAll(final double[] array, final int off, final int len) {
        final int last = off + len - 1;
        double tmp;

        for (int i = off, j = last; i < j; i++, j--) {
            tmp = array[i];
            array[i] = array[j];
            array[j] = tmp;
        }
    }
}

Related

  1. swap(T[] elements, int i, int j)
  2. swap(T[] ts, int i, int j)
  3. swap2(double v[], int v2[], int i, int j)
  4. swap2Bytes(byte[] bytes, int offset)
  5. swap3(String[] a, int x, int y, int z)
  6. swapAndPrint(int[] arr, int m, int n)
  7. swapArray(int[] v, int i, int j)
  8. swapArrayStr(String[] arr)
  9. swapArrayValues(int i1, int i2, int[] indices)