Page 1 of 1

Matcher class hitEnd method

Posted: Sat Aug 31, 2013 11:12 am
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.

Re: Matcher class hitEnd method

Posted: Sun Sep 01, 2013 7:18 am
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.