StringCharacterIterator previous Example

StringCharacterIterator class previous example. This example shows you how to use previous method.


StringCharacterIterator class previous example. char previous() Decrements the iterator's index by one and returns the character at the new index. If the current index is getBeginIndex(), the index remains at getBeginIndex() and a value of DONE is returned.

Here is the code
/*
 * @ # Previous.java
 * A class representing use to previous method of
 * StringCharacterIterator class in java.text package
 * version 13 June 2008
 * author Rose India 
 */

import java.text.*;

public class Previous {

    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

Post Comment
Name:
E-mail:
Contact no :
Comments:
  Refresh Image
Verify Image:
 
 
Your Comment's
 
 
 

HOME | COPYRIGHT | CONTACT US