A Scanner
allows you to read in text from some sort of input (e.g. a file or an InputStream
). That text is naturally a String
(because it's a sequence of bytes, which Scanner
interprets as characters). You can read the strings with .next()
and .nextLine()
, which read a single "word" token or a single line at a time, and which you can inspect with hasNext()
and hasNextLine()
.
Scanner
also provides the primitive methods as a convenience for reading in tokens that can be safely converted into primitives (e.g. int
and double
), so that you don't have to write convoluted integer-parsing code and the like.
But if all you need is strings, just use hasNext()
and next()
, or hasNextLine()
and nextLine()
. There is no need to check whether the input is a String
or not, because anything the user types is a string. Be sure to read the docs describing how Scanner
splits words/tokens up as well.