Reputation: 63
I saw on another question of how to read in exactly one character in Scanner this example...
char c = reader.next(".").charAt(0);
I was wondering what the (".")
means. What is the difference between that and this: char c = reader.next().charAt(0);
?
Upvotes: 1
Views: 64
Reputation: 12819
According to the docs for next(String pattern)
Returns the next token if it matches the pattern constructed from the specified string. If the match is successful, the scanner advances past the input that matched the pattern.
And where in this example, .
is
a string specifying the pattern to scan
The difference between char c = reader.next(".").charAt(0);
and
reader.next().charAt(0);
is that next(".")
returns the next token matching the pattern .
and next()
:
Finds and returns the next complete token from this scanner.
Upvotes: 3