All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class java.text.StringCharacterIterator

java.lang.Object
   |
   +----java.text.StringCharacterIterator

public final class StringCharacterIterator
extends Object
implements CharacterIterator
StringCharacterIterator implements the CharacterIterater protocol for a String. The StringCharacterIterator class iterates over the entire String.

Examples:

Traverse the text from start to finish

 public void traverseForward(CharacterIterator iter) {
     for (char c = iter.first(); c != CharacterIterator.DONE; c = iter.next()) {
         processChar(c);
     }
 }
 
Traverse the text backwards, from end to start
 public void traverseBackward(CharacterIterator iter) {
     for (char c = iter.last(); c != CharacterIterator.DONE; c = iter.prev()) {
         processChar(c);
     }
 }
 
Traverse both forward and backward from a given position in the text.
 public void traverseOut(CharacterIterator iter, int pos) {
     for (char c = iter.setIndex(pos);
          c != CharacterIterator.DONE && notBoundary(c);
          c = iter.next()) {}
     int end = iter.getIndex();
     for (char c = iter.setIndex(pos);
          c != CharacterIterator.DONE && notBoundary(c);
          c = iter.prev()) {}
     int start = iter.getIndex();
     processSection(iter.getText.subString(start,end);
 }
 


Constructor Index

 o StringCharacterIterator(String)
Construct an iterator with an initial index of 0.
 o StringCharacterIterator(String, int)
Construct an iterator with the specified initial index.
 o StringCharacterIterator(String, int, int, int)
Construct an iterator over the given range of the given string, with the index set at the specified position.

Method Index

 o clone()
Create a copy of this boundary
 o current()
Get the character at the current position (as returned by getIndex()).
 o equals(Object)
Compares the equality of two StringCharacterIterator objects.
 o first()
Set the position to getBeginIndex() and return the character at that position.
 o getBeginIndex()
Return the start index of the text.
 o getEndIndex()
Return the end index of the text.
 o getIndex()
Return the current index.
 o hashCode()
Compute a hashcode for this enumeration
 o last()
Set the position to getEndIndex() and return the character at that position.
 o next()
Increment the iterator's index by one and return the character at the new index.
 o previous()
Decrement the iterator's index by one and return the character at the new index.
 o setIndex(int)
Set the position to specified position in the text and return that character.

Constructors

 o StringCharacterIterator
    method StringCharacterIterator(text=String) public 
Construct an iterator with an initial index of 0.

 o StringCharacterIterator
    method StringCharacterIterator(text=String, -
                                   pos=int) public 
Construct an iterator with the specified initial index.

Parameters:
text - The String to be iterated over
pos - Initial iterator position
 o StringCharacterIterator
    method StringCharacterIterator(text=String, -
                                   begin=int, -
                                   end=int, -
                                   pos=int) public 
Construct an iterator over the given range of the given string, with the index set at the specified position.

Parameters:
text - The String to be iterated over
begin - Index of the first character
end - Index of the character following the last character
pos - Initial iterator position

Methods

 o first
    method first() returns char public     
Set the position to getBeginIndex() and return the character at that position.

 o last
    method last() returns char public     
Set the position to getEndIndex() and return the character at that position.

 o setIndex
    method setIndex(p=int) returns char public     
Set the position to specified position in the text and return that character.

 o current
    method current() returns char public     
Get the character at the current position (as returned by getIndex()).

Returns:
the character at the current position or DONE if the current position is off the end of the text.
 o next
    method next() returns char public     
Increment the iterator's index by one and return the character at the new index. If the resulting index is greater or equal to getEndIndex(), the current index is reset to getEndIndex() and a value of DONE is returned.

Returns:
the character at the new position or DONE if the current position is off the end of the text.
 o previous
    method previous() returns char public     
Decrement the iterator's index by one and return the character at the new index. If the resulting index is less than getBeginIndex(), the current index is reset to getBeginIndex() and a value of DONE is returned.

Returns:
the character at the new position or DONE if the current position is off the end of the text.
 o getBeginIndex
    method getBeginIndex() returns int public     
Return the start index of the text.

Returns:
the index at which the text begins.
 o getEndIndex
    method getEndIndex() returns int public     
Return the end index of the text. This index is the index of the first character following the end of the text.

Returns:
the index at which the text end.
 o getIndex
    method getIndex() returns int public     
Return the current index.

Returns:
the current index.
 o equals
    method equals(obj=Object) returns boolean public     
Compares the equality of two StringCharacterIterator objects.

Parameters:
obj - the StringCharacterIterator object to be compared with.
Returns:
true if the given obj is the same as this StringCharacterIterator object; false otherwise.
Overrides:
equals in class Object
 o hashCode
    method hashCode() returns int public     
Compute a hashcode for this enumeration

Returns:
A hash code
Overrides:
hashCode in class Object
 o clone
    method clone() returns Object public     
Create a copy of this boundary

Returns:
A copy of this
Overrides:
clone in class Object

All Packages  Class Hierarchy  This Package  Previous  Next  Index