Why not nextString instead of nextLine | Sololearn: Learn to code for FREE!


Why not nextString instead of nextLine

im a bit confused why they didn't use nextString? can someone please explain for a noob.

4/18/2017 9:37:58 PM


6 Answers

New Answer


lets say you have a string String str = "Hello World!"; Scanner scan = new Scanner (str); scan.next (); vs scan.nextLine (); scan.nextLine () would give: Hello World! while scan.next () would give: Hello nextLine gives the whole line, which next only gives the next word


because there is already a method for nextString. but its called next()


yes. the line could include integers and decimal numbers, except it would be returned as a string and in the case of only next (), even if it is an integer, it will be converted to a string, unless you do nextInt ()


so does that mean next() would only print the first word of the string?


i mean one line can be put in one string no?


so the line could also include integers etc? i think i got it. big thanks.😁