How do I reverse a string using CharacterIterator?
Category: java.text, viewed: 779 time(s).
In this example we use the CharacterIterator implementation class StringCharacterIterator to reverse a string. It's done by reading a string from the last index up to the beginning of the string.
package org.kodejava.example.text; import java.text.CharacterIterator; import java.text.StringCharacterIterator; public class ReverseStringCharacterExample { private static final String text = "Jackdaws love my big sphinx of quartz"; public static void main(String[] args) { CharacterIterator it = new StringCharacterIterator(text); // // Iterates a string from the last index to the beginning. // for (char ch = it.last(); ch != CharacterIterator.DONE; ch = it.previous()) { System.out.print(ch); } } } |
Related Examples
- How do I format a number with leading zeros?
- How do I parse a number for a locale?
- How do I format a number for a locale?
- How do I iterate a subset of a string?
- How do I iterate each characters of a string?
- How do I format a date-time value?
- How do I format a date into dd/mm/yyyy?
- How do I format a number?
- How do I convert Date to String?
- How do I Get a List of Weekday Names?
|
|