Matcher class hitEnd method

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
The_Nick
Posts: 132
Joined: Thu May 16, 2013 9:23 am
Contact:

Matcher class hitEnd method

Post by The_Nick »

Directly from the official API: http://docs.oracle.com/javase/1.5.0/doc ... tcher.html
hitEnd

public boolean hitEnd()

Returns true if the end of input was hit by the search engine in the last match operation performed by this matcher.

When this method returns true, then it is possible that more input would have changed the result of the last search.

Returns:
true iff the end of input was hit in the last match; false otherwise
Since:
What do they mean with their latter statement?

When this method returns true, then it is possible that more input would have changed the result of the last search.


Thanks in advance.

The_Nick.

admin
Site Admin
Posts: 10386
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: Matcher class hitEnd method

Post by admin »

It basically means that there was a partial match at the end. For example, if you search for "cat" it in "bobca", it will return true.

Code: Select all

    String sp1 = "cat";
    Pattern p1 = Pattern.compile(sp1);
    String str = "bobca";
    Matcher m = p1.matcher(str);
    while(m.find()){
    }
    System.out.println(m.hitEnd());
So it is telling you that if there was more text available in the input string, it could have found a match. In this case, had there been a 't' at the end, it could have found a match.

HTH,
Paul.

Post Reply

Who is online

Users browsing this forum: No registered users and 9 guests