//*****************************************************************************
// Convert a String array that might have nulls to double                           
//*****************************************************************************
import java.util.Arrays;

public class string2double  
{
    public static void main(String[] args)
    {
        String[] strArray = {"1.1","2.2","3","4",null,"6","7","8","-9.5"};
        double[] numArray;

        System.out.println("String array:    " + Arrays.toString(strArray));
        System.out.println("length or array: " + strArray.length + "\n");

        numArray = string2double(strArray);

        System.out.println("double array:    " + Arrays.toString(numArray));
        System.out.println("length or array: " + numArray.length + "\n");

        compute(strArray);
        compute(numArray);
    }

//*****************************************************************************
// Convert a String array that might have nulls to double
// If string array has null data, store Double.NaN in numeric array                            
//*****************************************************************************
    static double[] string2double(String[] strArray)
    {
        double[] numArray = new double[strArray.length];

        for (int i=0; i<strArray.length; i++)
        {
            if (strArray[i] == null)
                numArray[i] = Double.NaN;                       //store a special Double value "Not a Number"
            else
                numArray[i] = Double.parseDouble(strArray[i]);  //convert String to double
        }           
        return numArray;
    }

//*****************************************************************************
// Count and Sum a numeric array that might have (NaN) elements 
//*****************************************************************************
    static void compute(double[] numArray)
    {
        int count  = 0;
        double sum = 0;

        for (double num : numArray)
            if (! Double.isNaN(num))                            //test if element is Not a Number
            {
                count += 1;
                sum   += num;
            }    

        System.out.println("double array count: " + count);
        System.out.println("double array sum:   " + sum);
    }

//*****************************************************************************
// Count and Sum a String array that might have null/bad elements
//*****************************************************************************
    static void compute(String[] strArray)
    {
        int count  = 0;
        double sum = 0;

        for (String str : strArray)                         //loop through incoming string array
            try
            {
                double num = Double.parseDouble(str);       //convert from String to double 
                count += 1;                                 //if OK, count
                sum   += num;                               //and sum              
            } 
            catch(Exception e)                              //if error in conversion, skip it
            {}

        System.out.println("String array count: " + count);
        System.out.println("String array sum:   " + sum);
    }
}