Skip to content

Instantly share code, notes, and snippets.

@SiAust
Last active May 31, 2020 09:32
Show Gist options
  • Select an option

  • Save SiAust/eca1234540401ef3ea338a3bd4e18954 to your computer and use it in GitHub Desktop.

Select an option

Save SiAust/eca1234540401ef3ea338a3bd4e18954 to your computer and use it in GitHub Desktop.
Mapping a string input to int array using streams.
String[] words = new Scanner(System.in).nextLine().split(" ");
int[] intArray = Arrays.stream(words).mapToInt(Integer::parseInt).toArray();
System.out.println(Arrays.toString(intArray));
// Alternative
int[] intArray = Arrays.stream(new Scanner(System.in).nextLine().split(" "))
.mapToInt(Integer::parseInt)
.toArray();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment