You could, also, obtain the array directly from a split:
String input; //Obtained somewhere
...
int[] result = Arrays.stream(input.split(" "))
.mapToInt(Integer::valueOf)
.toArray();
Here, Arrays
has some nice methods to obtain the stream from an array, so you can split it directly in the call. After that, call mapToInt
with Integer::valueOf
to obtain the IntStream
and toArray
for your desired int array.