/** * Sets the position to getEndIndex()-1 (getEndIndex() if * the text is empty) and returns the character at that position. * <br><b>Specified by:</b> java.text.CharacterIterator. */ public char last() { return iter.last(); }
/** * Sets the position to getEndIndex()-1 (getEndIndex() if * the text is empty) and returns the character at that position. * <br><b>Specified by:</b> java.text.CharacterIterator. */ public char last() { return iter.last(); }
/** * Sets the position to getEndIndex()-1 (getEndIndex() if * the text is empty) and returns the character at that position. * <br><b>Specified by:</b> java.text.CharacterIterator. */ public char last() { return iter.last(); }
public static String reverse(final String value) { if (value != null) { final CharacterIterator it = new StringCharacterIterator(value); final StringBuilder buffer = new StringBuilder(); for (char c = it.last(); c != CharacterIterator.DONE; c = it.previous()) { buffer.append(c); } return buffer.toString(); } return value; }
CharacterIterator it = new StringCharacterIterator("abcd"); // Iterate over the characters in the forward direction for (char ch=it.first(); ch != CharacterIterator.DONE; ch=it.next()) // Iterate over the characters in the backward direction for (char ch=it.last(); ch != CharacterIterator.DONE; ch=it.previous())
import java.text.CharacterIterator; import java.text.StringCharacterIterator; public class CI { private static final String text = "Hello"; 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); } } }
private static String removeTrailingSlashes(final String text) { if (text.isEmpty()) { return text; } final CharacterIterator it = new StringCharacterIterator(text); Character c = it.last(); while (c.equals('/')) { c = it.previous(); } return text.substring(0, it.getIndex() + 1); }