Java Array Convert to toIntArray(double[] a)

Here you can find the source of toIntArray(double[] a)

Description

to Int Array

License

Open Source License

Declaration

public final static int[] toIntArray(double[] a) 

Method Source Code

//package com.java2s;

import java.util.Collection;
import java.util.Iterator;

public class Main {
    /**/*from  w  w w  . jav  a 2  s . c  om*/
     * Converts a List of Integer to an int[]
     * @param list
     * @return an array of int
     */
    public final static int[] toIntArray(Collection<Integer> list) {
        int[] res = new int[list.size()];
        int index = 0;
        Iterator<Integer> iter = list.iterator();
        while (iter.hasNext()) {
            Integer i = (Integer) iter.next();
            res[index++] = i.intValue();
        }
        return res;
    }

    public final static int[] toIntArray(double[] a) {
        int[] res = new int[a.length];
        for (int i = 0; i < a.length; i++) {
            res[i] = (int) a[i];
        }
        return res;
    }
}

Related

  1. toDoubleArray(byte[] data)
  2. toDoubleArray(Double[] list)
  3. toDoubleArray(final int[] intArray)
  4. toFloatArray(final double[] doubles)
  5. toInt(Integer[] arr)
  6. toIntArray(Integer[] data)
  7. toLongArray(int[] array)
  8. toLongArray(String[] array)