Hi, Can anyone suggest some good study material for Scanner and Formatter classes. I have read Sybex Complete Java 2 Certification, But i think the material in this book regarding Scanner is not sufficient.
Thanx for your help
Regards<br />Sandy<br />[SCJP 5.0 - 75%]<br />[SCWCD 1.4 - 85%]<br />------------------<br />Tiger, Tiger burning bright,<br />Like a geek who works all night,<br />What new-fangled bit or byte,<br />Could ease the hacker's weary plight?
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