Convert String[] array to double[] array using Apache Commons

This code example shows how to convert a string array to a double array.

For this we use the Apache Commons Beanutils library that comes with quite a few converters for different data types. It also comes with a utility class containing methods to do conversions without directly using the converter for that specific type. That utility class is called ConvertUtils and it takes an object and a class type as parameters and return an object. That is why we have to cast the result from the convert object to a double array.

If any of the values in the string array is not in form of a number, it will be converted to zero.

The below example shows how to use it to convert a string array to a double array.

The output from the code above is:

Search for more Java info on this site here:
Custom Search

Any thoughts or questions?