previous | start | next

How to read input one character at a time

The Scanner class has a method:

      public Scanner useDelimiter(String pattern)
   

The default pattern matches any sequence of whitespace characters (blank ' ', tab '\t', newline '\n', carriage return '\r' and a few more)

So the next() method will skip leading string made up of the delimiter characters and stop at trailing delimiter characters or end of input.

Setting the delimter to the empty string causes the next() method to not skip any leading characters and it will read a string consisting of just one character.



previous | start | next