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