Use CharacterIterator to loop through a string : CharacterIterator « Development Class « Java

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 =; 
    ch = it.current(); 
    ch = it.last(); 
    int pos = it.getIndex(); 
    ch =; 
    pos = it.getIndex(); 
    ch = it.previous(); 
    ch = it.setIndex(1);


Related examples in the same category

1.Reverse a string using CharacterIterator
2.Iterate each characters of a string
3.Iterate a subset of a string
4.Iterating the Characters of a String
5.Iterate over the characters in the backward direction
6.Change the characters
7.Create an iterator on a substring (efgh)