Convert double array to Float Array - Java Collection Framework

Java examples for Collection Framework:Array Convert

Description

Convert double array to Float Array

Demo Code


import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
import java.util.function.Predicate;

public class Main{
    public static void main(String[] argv){
        double[] doubleArray = new int[]{34.45,35.45,36.67,37.78,37.0000,37.1234,67.2344,68.34534,69.87700};
        System.out.println(java.util.Arrays.toString(toFloatArray(doubleArray)));
    }// w w w .java  2 s .  c  om
    static float[] toFloatArray(final double[] doubleArray) {
    if (doubleArray == null) {
      return null;
    } else {
      final int size = doubleArray.length;
      final float[] floatArray = new float[size];
      for (int i = 0; i < size; i++) {
        floatArray[i] = (float)doubleArray[i];
      }
      return floatArray;
    }
  }
}

Related Tutorials