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 441 times
        
    0
            
            
         
    
    
        kryger
        
- 12,906
- 8
- 44
- 65
- 
                    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
1
            
            
        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
        
- 467
- 4
- 15
