StringCharacterIterator last Example
StringCharacterIterator class last example. This example shows you how to use last method.
StringCharacterIterator class last example. char last() Sets the position to getEndIndex()-1 (getEndIndex() if the text is empty) and returns the character at that position.
Here is the code
/*
* @ # Last.java
* A class representing use to last method of
* StringCharacterIterator class in java.text package
* version 13 June 2008
* author Rose India
*/
import java.text.*;
public class Last {
public static void main(String args[]) {
StringCharacterIterator s =
new StringCharacterIterator("Rose");
for (char ch = s.last(); ch != CharacterIterator.DONE;
ch = s.previous()) {
System.out.println("Index of character '" +
s.current() + "' is " + s.getIndex());
}
}
} |
Output
Index of character 'e' is 3
Index of character 's' is 2
Index of character 'o' is 1
Index of character 'R' is 0 |
|