aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes MatchResult.start() & MatchResult.end() methods Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "MatchResult.start() & MatchResult.end() methods" Watch "MatchResult.start() & MatchResult.end() methods" New topic
Author

MatchResult.start() & MatchResult.end() methods

Swapna Gouri Kalanidhi
Ranch Hand

Joined: Mar 14, 2008
Posts: 107
Hello All

Here are 2 programs given in JavaBeat Mock exam which are behaving differently.


The above program's output is 5
The next program goes like this...


And the output of this is 2 followed by 8

In the first program we are using scanner.match.start(). In the second one we are using scanner.match.end(). What's the indexing of these two methods? Do they use zero as starting index or 1? Can any one explain me their behavior??? Thanks all!
[ July 08, 2008: Message edited by: Swapna Gouri Kalanidhi ]

Thanks & Regards
Swapna Gouri
I "try", I "catch" and "finally" WIN !!!
Ralph Jaus
Ranch Hand

Joined: Apr 27, 2008
Posts: 342
Hi Swapna Gouri,

I'll try to explain the results. Let's start with the first one.

1. The first scanner.next() finds "ai ".
2. The second scanner.next() finds "ello".
3. scanner.match().start() returns the starting position of the substring "ello" in the original string "hai hello". This
is 5.
4. scanner.match().end() returns the position after the substring (see API documentation for MatchResult). This is 9.

The second example works in the same fashion. If it still makes problems, just let us know.
[ July 08, 2008: Message edited by: Ralph Jaus ]

SCJP 5 (98%) - SCBCD 5 (98%)
Swapna Gouri Kalanidhi
Ranch Hand

Joined: Mar 14, 2008
Posts: 107
Thank you Ralph, I got the point. But I still have a doubt, does these methods,viz., match.start()& match.end() use zero indexing or 1 indexing? I mean should we start counting the alphabets from 0 or from 1??
Swapna Gouri Kalanidhi
Ranch Hand

Joined: Mar 14, 2008
Posts: 107
Hello Ralph
Thanks for explaining the behavior of the start() & end() methods. i have tried both the methods practically & I have understood the concept. Thanks a lot for giving a detailed description how both of them work...!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: MatchResult.start() & MatchResult.end() methods