Java Float Array Create toFloats(Float[] values)

Here you can find the source of toFloats(Float[] values)

Description

to Floats

License

Open Source License

Declaration

public static float[] toFloats(Float[] values) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static final float DEFAULT_FLOAT = 0f;

    public static float[] toFloats(Float[] values) {
        return toFloats(values, DEFAULT_FLOAT);
    }//from w  w w . j  a v a2 s .c  o  m

    public static float[] toFloats(Float[] values, float defaultValue) {
        float[] results = new float[0];
        if (values != null) {
            results = new float[values.length];
            for (int i = 0; i < results.length; i++) {
                Float element = values[i];
                try {
                    results[i] = (element != null ? element.floatValue()
                            : defaultValue);
                } catch (Exception ex) {
                    // ex.printStackTrace();
                }
            }
        }
        return results;
    }

    public static Float[] toFloats(float[] values) {
        return toFloats(values, DEFAULT_FLOAT);
    }

    public static Float[] toFloats(float[] values, float defaultValue) {
        Float[] results = new Float[0];
        if (values != null) {
            results = new Float[values.length];
            for (int i = 0; i < results.length; i++) {
                float element = values[i];
                try {
                    results[i] = new Float(element);
                } catch (Exception ex) {
                    results[i] = defaultValue;
                    // ex.printStackTrace();
                }
            }
        }
        return results;
    }
}

Related

  1. toFloatRawBits(int i)
  2. toFloats(byte[] bytes)
  3. toFloats(byte[] value, int offset, int num)
  4. toFloats(double[] d)
  5. toFloats(final double[] array)
  6. toFloats(Object[] extraArgs)
  7. toFloats(String floatArray)
  8. toFloatValue(Object number)
  9. toFloatWithoutOverflow(double value)