To further understand how the Scanner class works, we must first understand how the input is handled.

To do this, we learn about the concept of an input token, a delimiter, and an input stream.

  • A delimiter is any character or sequence of distinct characters that separates the input string into smaller portions of characters called tokens.

    For example, if we have the following input:

    and we set our delimiter as " ", then these smaller strings divided by the delimiter are what we call tokens.

  • Likewise, a token is any sequence of characters from the input separated by a delimiter.
    As an example, if we have the delimiter ",", and the following input:

    Therefore, we can separate the input into two tokens, as displayed by the following:

  • A stream is any set of tokens arranged in a sequence.
    For example in an input string: abc 123 true 3.14, the first token in the stream is abc, the second token in the stream is 123, and so on.

Using delimiters and tokens, we can have a good idea of how Scanner works.