Java Double Array to Short Array doublesToShorts(final double[] array)

Here you can find the source of doublesToShorts(final double[] array)

Description

convert an array of double values to an array of short .

License

Open Source License

Parameter

Parameter Description
array the array of double

Return

the array of short

Declaration

public static final short[] doublesToShorts(final double[] array) 

Method Source Code

//package com.java2s;
//License from project: MIT License 

public class Main {
    /**/*from  w w  w  .j a v a  2  s.c  o  m*/
     * convert an array of {@code double} values to an array of {@code short}
     * .
     *
     * @param array
     *          the array of {@code double}
     * @return the array of {@code short}
     */
    public static final short[] doublesToShorts(final double[] array) {
        final short[] res;
        int i;

        res = new short[array.length];
        i = 0;
        for (final double x : array) {
            res[i++] = ((short) x);
        }

        return res;
    }
}