DEV Community

Discussion on: Be Careful with Scanner Methods in Java

Collapse
 
undermark5 profile image
undermark5

So, this isn't just a problem that Java has. C++ had this same issue as well. Combining cin and getline in C++ results in the same behavior.

This also isn't really a problem, if you understand that it skips delimiter, reads, then stops at the next delimiter. nextLine is really the special one in the situation because it uses it's own delimiter separate from the scanner's and reads past it's delimiter and returns everything read, but the delimiter.

Collapse
 
renegadecoder94 profile image
Jeremy Grifski

Agreed! I'm aware of how these tools work, but you have to keep in mind who this piece is targeting. Beginners don't usually have the bandwidth to tackle the intricacies of parsing when they just want to get some user input.