0

Why not nextString instead of nextLine

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

18th Apr 2017, 9:37 PM
serdox
serdox - avatar
6 Antworten
+ 3
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
18th Apr 2017, 10:10 PM
Edward
+ 3
because there is already a method for nextString. but its called next()
18th Apr 2017, 9:39 PM
Edward
+ 2
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 ()
19th Apr 2017, 1:09 AM
Edward
0
so does that mean next() would only print the first word of the string?
18th Apr 2017, 9:51 PM
serdox
serdox - avatar
0
i mean one line can be put in one string no?
18th Apr 2017, 9:52 PM
serdox
serdox - avatar
0
so the line could also include integers etc? i think i got it. big thanks.😁
18th Apr 2017, 10:11 PM
serdox
serdox - avatar