Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

a few questions about Scanner  RSS feed

 
Jay Dilla
Ranch Hand
Posts: 201
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not understanding how I'm supposed to scan in whole strings.
I tried to use the delimiter and put " " as the delimiter but it still just returned the first word if i put in two words



so i'm guessing sc.next isn't the proper method to use , but there doesn't seem to be a method that will scan in multiple words

Also what if i'm scanning input in from the system , ie: new Scanner(System.in), but I don't know the type of input being entered. what can i use as a sort of "catch all" that will just pull it all in as string or something
 
Campbell Ritchie
Marshal
Posts: 55717
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Go through the Scanner class in the API and look for methods like nextLine.
A Scanner doesn't usually scan multiple words (actually called tokens); it gets the next token as a word (String) or an int, a double, etc etc.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!