Java Array Convert to toFloatArray(final double[] doubles)

Here you can find the source of toFloatArray(final double[] doubles)

Description

to Float Array

License

Open Source License

Parameter

Parameter Description
doubles a parameter

Return

float[]

Declaration

public static float[] toFloatArray(final double[] doubles) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Manchester Centre for Integrative Systems Biology
 * University of Manchester/*ww w .j a  v a2 s.c om*/
 * Manchester M1 7ND
 * United Kingdom
 * 
 * Copyright (C) 2007 University of Manchester
 * 
 * This program is released under the Academic Free License ("AFL") v3.0.
 * (http://www.opensource.org/licenses/academic.php)
 *******************************************************************************/

import java.util.*;

public class Main {
    /**
     * 
     * @param doubles
     * @return float[]
     */
    public static float[] toFloatArray(final double[] doubles) {
        final float[] floats = new float[doubles.length];

        for (int i = 0; i < doubles.length; i++) {
            floats[i] = (float) doubles[i];
        }

        return floats;
    }

    /**
     * 
     * @param collection
     * @return float[]
     */
    public static float[] toFloatArray(final Collection<Float> collection) {
        final float[] array = new float[collection == null ? 0 : collection.size()];

        if (collection != null) {
            int i = 0;

            for (Iterator<Float> iterator = collection.iterator(); iterator.hasNext();) {
                array[i++] = iterator.next().floatValue();
            }
        }

        return array;
    }
}

Related

  1. convertArrayTypeName(final String typeName)
  2. convertArrayValue(Object value, Class type)
  3. toDoubleArray(byte[] data)
  4. toDoubleArray(Double[] list)
  5. toDoubleArray(final int[] intArray)
  6. toInt(Integer[] arr)
  7. toIntArray(double[] a)
  8. toIntArray(Integer[] data)
  9. toLongArray(int[] array)