Thursday, September 8, 2011

Java: Iterate a String


java.text.CharacterIterator;
java.text.StringCharacterIterator;
CharacterIterator it = new StringCharacterIterator("abcd");

// Iterate over the characters in the forward direction
for (char ch=it.first(); ch != CharacterIterator.DONE; ch=it.next()) {
    // Use ch ...
}
Reference:
http://www.exampledepot.com/egs/java.text/StrIter.html

No comments: