Create an iterator on a substring (efgh) : CharacterIterator « Development Class « Java






Create an iterator on a substring (efgh)


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

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

    int begin = 5;
    int end = 9;
    int pos = 6;
    it = new StringCharacterIterator("abcd efgh ijkl", begin, end, pos);
    char ch = it.current();
    System.out.println(ch);
    ch = it.last();
    System.out.println(ch);
  }
}

 








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.Use CharacterIterator to loop through a string
7.Change the characters