Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
String s = sc.nextLine();
String[] arr = s.split(" ");
//not able to split the string by whitespace" ".
Asked
Active
Viewed 51 times
0
![](../../users/profiles/1240557.webp)
kryger
- 11,746
- 8
- 41
- 60
-
Does this help: [Scanner is skipping nextLine() after using next() or nextFoo()?](https://stackoverflow.com/questions/13102045/scanner-is-skipping-nextline-after-using-next-or-nextfoo) – Abra Apr 09 '20 at 11:52
1 Answers
0
nextLine
here reads the rest of the line first according to the docs, so you need another call to nextLine
.
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
sc.nextLine(); // added
String s = sc.nextLine();
String[] arr = s.split(" ");
![](../../users/profiles/6877477.webp)
Anton Kahwaji
- 427
- 6
- 12