Java Integer Array Convert To copySignedIntToShortArray(int[] src)

Here you can find the source of copySignedIntToShortArray(int[] src)

Description

Copy an array of signed values in int, into an array of short.

The value is truncated as necessary.

License

Open Source License

Parameter

Parameter Description
src an array of int

Return

an array of short

Declaration

static public short[] copySignedIntToShortArray(int[] src) 

Method Source Code

//package com.java2s;

public class Main {
    /**//from   w  ww .j a v a2s.co m
     * <p>Copy an array of signed values in int, into an array of short.</p>
     *
     * <p>The value is truncated as necessary.</p>
     *
     * @param   src   an array of int
     * @return      an array of short
     */
    static public short[] copySignedIntToShortArray(int[] src) {
        if (src == null)
            return null;
        int n = src.length;
        short[] dst = new short[n];
        for (int j = 0; j < n; ++j) {
            dst[j] = (short) (src[j]); // truncates
        }
        return dst;
    }
}

Related

  1. copySignedIntToDoubleArray(int[] src)
  2. intArray2HashCode(int[] xs)
  3. intArray2HexString(int[] intArray)
  4. intArray2IntegerArray(int[] array, int newLength)
  5. intArray2Json(int[] array)