Use CharacterIterator to loop through a string
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); } }