Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

public class Main {
    /**
     * <p>Extract decimal values from an array of strings into an array of float.</p>
     *
     * <p>Exceptions in the format of the string are trapped and 0 value(s) returned.</p>
     *
     * @param   src   an array of strings, each of which should be a decimal numeric value
     * @return      an array of float
     */
    static public float[] copyStringToFloatArray(String[] src) {
        if (src == null)
            return null;
        int n = src.length;
        float[] dst = new float[n];
        for (int j = 0; j < n; ++j) {
            float value = 0;
            try {
                value = Float.valueOf(src[j]).floatValue();
            } catch (NumberFormatException e) {
            } catch (NullPointerException e) {
            }
            dst[j] = value;
        }
        return dst;
    }
}