Here is some words I have put together on the subject of the Scanner class...
Scanner
The Scanner class makes it easier to break up input into managable data. The API documentation give a rather odd example of using the
word fish as a delimiter. I suspect that more commonly encountered delimters would be either a simple blank space or one of the characters used when exporting data such as a comma, or pipe symbol (|). To give a trivial example with the default white space delimiter.
If you run this code it will simply take three int values from the command line.
The following code is a little more interesting and is adapted from the example given in the API docs that uses a delimiter of �fish�
If you run this code with the command line
The output will be
Input: 1 , 2 ,
Delimiter: ,
1
2
However, the delimter will only match a single space character, what if you have a slightly irregular file that sometimes has more than one space between the numbers. The Scanner can use just about any standard regular expression, so you can use
Note that if you need to use any expression with regular expression meaning, e.g. The bar character sometimes used as a separator for data you will need to use the backslash character to �escape� it. Thus
Will parse the input and output only the numbers.