daydreamer daydreamer - 1 month ago 9
Java Question

How to convert String Array to Double Array in one line

I have a string array as:

String[] guaranteedOutput = Arrays.copyOf(values, values.length,
String[].class);


All the String values are numbers. The data should be converted to a
Double[]
.

Question

Is there a one line solution in Java to achieve this or we need to loop and convert each value to a Double?

Answer

Create a method implementing it using a loop, then call your method, and you'll have a one-line solution.

There is no buit-in method in the Java API to do that.