previous | start | next

Scanner: Reading whole lines

Since the Scanner next() method stops as soon as it encounters whitespace (a blank, tab, newline, carriage return) it can't be used directly to read a line that contains blanks such as a person's full name.

The Scanner class has a nextLine() method that reads the entire line. It returns the input line as a single String. The returned string does not include the end of line character.



previous | start | next