Roopam Samal wrote:If next token doesn't match Integer regular expression or out of range then InputMismatchException occurs
and here next token is "sue" which doesn't match Integer regular expression so this exception occured...
Is there any particular reason you're using
Scanner here?
String[] tokens = "5,sue,true,3".split(",");
would work just as well, and then:
1. You have
all the tokens in your string, rather than having to work through sequentially to get each one.
2. All those tokens are
Strings, and
now you can worry about converting them.
Personally, I don't particularly like
Scanner - mainly because I don't think it achieves what it set out to do (make getting different types, especially numbers, from Strings and files simpler) - but I know that Campbell and I disagree on this point.
However, that said, don't let me stop you from "discovering"
Scanner. That's what programming's all about.
Winston