java.lang.Object | +----java.text.StringCharacterIterator
public final class StringCharacterIterator
extends Object
implements CharacterIterator
StringCharacterIterator implements the CharacterIterater protocol for a String. The StringCharacterIterator class iterates over the entire String.
Examples:
Traverse the text from start to finish
public void traverseForward(CharacterIterator iter) { for (char c = iter.first(); c != CharacterIterator.DONE; c = iter.next()) { processChar(c); } }Traverse the text backwards, from end to start
public void traverseBackward(CharacterIterator iter) { for (char c = iter.last(); c != CharacterIterator.DONE; c = iter.prev()) { processChar(c); } }Traverse both forward and backward from a given position in the text.
public void traverseOut(CharacterIterator iter, int pos) { for (char c = iter.setIndex(pos); c != CharacterIterator.DONE && notBoundary(c); c = iter.next()) {} int end = iter.getIndex(); for (char c = iter.setIndex(pos); c != CharacterIterator.DONE && notBoundary(c); c = iter.prev()) {} int start = iter.getIndex(); processSection(iter.getText.subString(start,end); }