Last active
May 31, 2020 09:32
-
-
Save SiAust/eca1234540401ef3ea338a3bd4e18954 to your computer and use it in GitHub Desktop.
Mapping a string input to int array using streams.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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