public abstract class SearchIterator extends Object
SearchIterator defines a protocol for text searching. Subclasses provide concrete implementations of various search algorithms. For example, StringSearch implements language-sensitive pattern matching based on the comparison rules defined in a RuleBasedCollator object.
Other options for searching include using a BreakIterator to restrict the points at which matches are detected.
SearchIterator provides an API that is similar to that of other text iteration classes such as BreakIterator. Using this class, it is easy to scan through text looking for all occurrences of a given pattern. The following example uses a StringSearch object to find all instances of "fox" in the target string. Any other subclass of SearchIterator can be used in an identical manner.
String target = "The quick brown fox jumped over the lazy fox";
String pattern = "fox";
SearchIterator iter = new StringSearch(pattern, target);
for (int pos = iter.first(); pos != SearchIterator.DONE;
pos = iter.next()) {
System.out.println("Found match at " + pos +
", length is " + iter.getMatchLength());
}
BreakIterator
,
RuleBasedCollator
Modifier and Type | Class and Description |
---|---|
static class |
SearchIterator.ElementComparisonType
Option to control how collation elements are compared.
|
Modifier and Type | Field and Description |
---|---|
protected BreakIterator |
|