Java Array Shorten toShortArray(final byte[] array)

Here you can find the source of toShortArray(final byte[] array)

Description

to Short Array

License

Open Source License

Declaration

public static short[] toShortArray(final byte[] array) 

Method Source Code

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

public class Main {
    public static short[] toShortArray(final byte[] array) {
        return toShortArray(array, 0, array.length);
    }/* w  ww. ja v  a 2 s.c  o  m*/

    public static short[] toShortArray(final byte[] array, final int off, final int len) {
        return toShortArray(array, off, len, new short[len], 0);
    }

    public static short[] toShortArray(final byte[] from, final int fromOff, final int len, final short[] to,
            final int toOff) {
        final int end = fromOff + len;

        for (int i = fromOff, j = toOff; i < end; i++, j++) {
            to[j] = from[i];
        }

        return to;
    }

    public static short[] toShortArray(final char[] array) {
        return toShortArray(array, 0, array.length);
    }

    public static short[] toShortArray(final char[] array, final int off, final int len) {
        return toShortArray(array, off, len, new short[len], 0);
    }

    public static short[] toShortArray(final char[] from, final int fromOff, final int len, final short[] to,
            final int toOff) {
        final int end = fromOff + len;

        for (int i = fromOff, j = toOff; i < end; i++, j++) {
            to[j] = (short) from[i];
        }

        return to;
    }

    public static short[] toShortArray(final int[] array) {
        return toShortArray(array, 0, array.length);
    }

    public static short[] toShortArray(final int[] array, final int off, final int len) {
        return toShortArray(array, off, len, new short[len], 0);
    }

    public static short[] toShortArray(final int[] from, final int fromOff, final int len, final short[] to,
            final int toOff) {
        final int end = fromOff + len;

        for (int i = fromOff, j = toOff; i < end; i++, j++) {
            to[j] = (short) from[i];
        }

        return to;
    }

    public static short[] toShortArray(final long[] array) {
        return toShortArray(array, 0, array.length);
    }

    public static short[] toShortArray(final long[] array, final int off, final int len) {
        return toShortArray(array, off, len, new short[len], 0);
    }

    public static short[] toShortArray(final long[] from, final int fromOff, final int len, final short[] to,
            final int toOff) {
        final int end = fromOff + len;

        for (int i = fromOff, j = toOff; i < end; i++, j++) {
            to[j] = (short) from[i];
        }

        return to;
    }

    public static short[] toShortArray(final float[] array) {
        return toShortArray(array, 0, array.length);
    }

    public static short[] toShortArray(final float[] array, final int off, final int len) {
        return toShortArray(array, off, len, new short[len], 0);
    }

    public static short[] toShortArray(final float[] from, final int fromOff, final int len, final short[] to,
            final int toOff) {
        final int end = fromOff + len;

        for (int i = fromOff, j = toOff; i < end; i++, j++) {
            to[j] = (short) from[i];
        }

        return to;
    }

    public static short[] toShortArray(final double[] array) {
        return toShortArray(array, 0, array.length);
    }

    public static short[] toShortArray(final double[] array, final int off, final int len) {
        return toShortArray(array, off, len, new short[len], 0);
    }

    public static short[] toShortArray(final double[] from, final int fromOff, final int len, final short[] to,
            final int toOff) {
        final int end = fromOff + len;

        for (int i = fromOff, j = toOff; i < end; i++, j++) {
            to[j] = (short) from[i];
        }

        return to;
    }
}

Related

  1. toShortArray(byte[] data)
  2. toShortArray(double[][] array)
  3. toShortArray(long value, int length)
  4. toShortArray(Number[] array)
  5. toShortArray(Object[] array)
  6. toShortArray(String str, String separator)