Java Integer Create toInt(double[] array)

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

Description

1-D Double array to integer array.

License

BSD License

Parameter

Parameter Description
array Double array.

Return

Integer array.

Declaration

public static int[] toInt(double[] array) 

Method Source Code

//package com.java2s;
// under the BSD license. The original license terms are given below:

public class Main {
    /**/*w  w w.  j a  va  2 s. c  o m*/
     * 1-D Double array to integer array.
     * @param array Double array.
     * @return Integer array.
     */
    public static int[] toInt(double[] array) {
        int[] n = new int[array.length];
        for (int i = 0; i < array.length; i++) {
            n[i] = (int) array[i];
        }
        return n;
    }

    /**
     * 2-D Double array to integer array.
     * @param array Double array.
     * @return Integer array.
     */
    public static int[][] toInt(double[][] array) {
        int[][] n = new int[array.length][array[0].length];
        for (int i = 0; i < array.length; i++) {
            for (int j = 0; j < array[0].length; j++) {
                n[i][j] = (int) array[i][j];
            }
        }
        return n;
    }

    /**
     * 1-D Float array to integer array.
     * @param array Float array.
     * @return Integer array.
     */
    public static int[] toInt(float[] array) {
        int[] n = new int[array.length];
        for (int i = 0; i < array.length; i++) {
            n[i] = (int) array[i];
        }
        return n;
    }

    /**
     * 2-D Float array to integer array.
     * @param array Float array.
     * @return Integer array.
     */
    public static int[][] toInt(float[][] array) {
        int[][] n = new int[array.length][array[0].length];
        for (int i = 0; i < array.length; i++) {
            for (int j = 0; j < array[0].length; j++) {
                n[i][j] = (int) array[i][j];
            }
        }
        return n;
    }
}

Related

  1. toInt(double in)
  2. toInt(double num)
  3. toInt(double val)
  4. toInt(double value)
  5. toInt(double[] arr)
  6. toInt(double[] layer)
  7. toInt(double[] v)
  8. toInt(double[][] data)
  9. toInt(double[][] doubles)