Reverse a string using CharacterIterator : CharacterIterator « Development Class « Java






Reverse a string using CharacterIterator


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

public class Main {
  private static final String text = "this is a test";

  public static void main(String[] args) {
    CharacterIterator it = new StringCharacterIterator(text);

    for (char ch = it.last(); ch != CharacterIterator.DONE; ch = it.previous()) {
      System.out.print(ch);
    }
  }
}
 

 








Related examples in the same category

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