aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Scanner and MatchResult Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Scanner and MatchResult" Watch "Scanner and MatchResult" New topic
Author

Scanner and MatchResult

jan ter avest
Ranch Hand

Joined: Dec 18, 2006
Posts: 46
The following code is from the WhizLabs simulator:
class ScannerTest {
public static void main( String[] args ) {
String input = "1 done 2 done all done";
Scanner s = new Scanner(input);
s.findInLine("(\\d+) done (\\d+) done (\\w+)

done");
MatchResult result = s.match();
for (int i=1; i<= result.groupCount(); i++)// line a
System.out.print(result.group(i)+ " " ); // line b
s.close();
}
}

the code runs and compiles and output 1 2 all.

Here's my question: if I replace line a and b with just:
System.out.print(result.group() + " ");

Why does the code throw a runtime IllegalStateException, no match result available??


SCJP1.5 SCWCD1.5
Javier Sanchez Cerrillo
Ranch Hand

Joined: Aug 02, 2006
Posts: 152
Aghhhhhhhhhhhh. I have seen that Interface in Whizlabs too!!!. Does MatchResult come in the exam???


SCJP 5.0 95%<br /> <br />The greatest enemy of knowledge is not ignorance, it is the illusion of knowledge.
jan ter avest
Ranch Hand

Joined: Dec 18, 2006
Posts: 46
Not according to the KB book.

WhizLabs tends to squeeze in some off-topic/extra material in its questions, in my opinion.

Btw, know of any other recommendable simulators? Im only using the whizlabs one at the moment...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Scanner and MatchResult