Java convert String[] to int[]

Viewed 12759

I have a String[], where each element is convertible to an integer. What's the best way I can convert this to an int[]?

int[] StringArrayToIntArray(String[] s)
{
    ... ? ...
}
5 Answers

convert String[] to Integer[] in java 8:

Integer[] myArray = Stream.of(new String[] { "1", "2", "3" })
        .map(Integer::parseInt)
        .toArray(Integer[]::new);
Related