[Java Basics] Scanner'The difference between next() method and nextLine() method'

Detailed explanation of the difference between next() and nextLine()

next() method :

When reading the content, it will filter out the invalid characters before the valid characters. The next() method will automatically filter out the end characters such as the space bar, Tab key or Enter key that are encountered before the valid character is entered;

Only after reading a valid character, the next() method treats the following space, Tab, or Enter as a terminator; therefore, the next() method cannot get a string with spaces.

nextLine() method:

This method literally means scanning a whole line, and its terminator can only be the Enter key, that is, the nextLine() method returns all the characters that have not been read before the Enter key, and it can get a string with spaces of.  
 

Guess you like

Origin blog.csdn.net/qq_44624536/article/details/114242383