0
 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" ".
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 Answers1

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(" ");
Anton Kahwaji
  • 427
  • 6
  • 12