Use CharacterIterator to loop through a string : CharacterIterator « I18N « Java Tutorial






import java.text.CharacterIterator;
import java.text.StringCharacterIterator;

public class Main {
  public static void main(String[] argv) throws Exception {
    CharacterIterator it = new StringCharacterIterator("abcd");

    char ch = it.first(); 
    ch = it.current(); 
    ch = it.next(); 
    ch = it.current(); 
    ch = it.last(); 
    int pos = it.getIndex(); 
    ch = it.next(); 
    pos = it.getIndex(); 
    ch = it.previous(); 
    ch = it.setIndex(1);
  }
}








13.21.CharacterIterator
13.21.1.Reverse a string using CharacterIterator
13.21.2.Iterate each characters of a string
13.21.3.Iterate a subset of a string
13.21.4.Iterating the Characters of a String
13.21.5.Iterate over the characters in the backward direction
13.21.6.Use CharacterIterator to loop through a string
13.21.7.Change the characters
13.21.8.Create an iterator on a substring (efgh)