Berry Berry - 1 year ago 59
Java Question

Is it possible to convert a string to an int[] using only lambda expressions?

I was thinking of converting this

1 2 3 4 5 6
to an
using only lambda expressions. I was thinking of something along the lines of

int[] x = Arrays.asList(scan.nextLine().split(" ")).stream.forEach(it -> Integer.parseInt(it));
but this is syntactically invalid.

Answer Source

Just a couple of small improvement on @Jason's answer to remove the conversion to list and return an int[] rather than Integer[]:

int[] result = Pattern.compile(" ").splitAsStream("1 2 3 4 5")
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download