Class StringCharacterIterator
java.lang.Object
java.text.StringCharacterIterator
- All Implemented Interfaces:
- Cloneable,- CharacterIterator
StringCharacterIterator implements the
 CharacterIterator protocol for a String.
 The StringCharacterIterator class iterates over the
 entire String. All constructors throw NullPointerException
 if text is null.- Since:
- 1.1
- See Also:
- 
Field SummaryFields declared in interface java.text.CharacterIteratorDONE
- 
Constructor SummaryConstructorsConstructorDescriptionConstructs an iterator with an initial index of 0.StringCharacterIterator(String text, int pos) Constructs an iterator with the specified initial index.StringCharacterIterator(String text, int begin, int end, int pos) Constructs an iterator over the given range of the given string, with the index set at the specified position.
- 
Method SummaryModifier and TypeMethodDescriptionclone()Creates a copy of this iterator.charcurrent()Implements CharacterIterator.current() for String.booleanCompares the equality of two StringCharacterIterator objects.charfirst()Implements CharacterIterator.first() for String.intImplements CharacterIterator.getBeginIndex() for String.intImplements CharacterIterator.getEndIndex() for String.intgetIndex()Implements CharacterIterator.getIndex() for String.inthashCode()Computes a hashcode for this iterator.charlast()Implements CharacterIterator.last() for String.charnext()Implements CharacterIterator.next() for String.charprevious()Implements CharacterIterator.previous() for String.charsetIndex(int p) Implements CharacterIterator.setIndex() for String.voidReset this iterator to point to a new string.
- 
Constructor Details- 
StringCharacterIteratorConstructs an iterator with an initial index of 0.- Parameters:
- text- the- Stringto be iterated over
 
- 
StringCharacterIteratorConstructs an iterator with the specified initial index.- Parameters:
- text- The String to be iterated over
- pos- Initial iterator position
- Throws:
- IllegalArgumentException- if- posis not within the bounds of range (inclusive) from- 0to the length of- text
 
- 
StringCharacterIteratorConstructs 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
- Throws:
- IllegalArgumentException- if- beginand- endare not within the bounds of range (inclusive) from- 0to the length of- text,- beginis greater than- end, or- posis not within the bounds of range (inclusive) from- beginto- end
 
 
- 
- 
Method Details- 
setTextReset this iterator to point to a new string. This package-visible method is used by other java.text classes that want to avoid allocating new StringCharacterIterator objects every time their setText method is called.- Parameters:
- text- The String to be iterated over
- Throws:
- NullPointerException- if- textis- null
- Since:
- 1.2
 
- 
firstpublic char first()Implements CharacterIterator.first() for String.- Specified by:
- firstin interface- CharacterIterator
- Returns:
- the first character in the text, or DONE if the text is empty
- See Also:
 
- 
lastpublic char last()Implements CharacterIterator.last() for String.- Specified by:
- lastin interface- CharacterIterator
- Returns:
- the last character in the text, or DONE if the text is empty
- See Also:
 
- 
setIndexpublic char setIndex(int p) Implements CharacterIterator.setIndex() for String.- Specified by:
- setIndexin interface- CharacterIterator
- Parameters:
- p- the position within the text. Valid values range from getBeginIndex() to getEndIndex(). An IllegalArgumentException is thrown if an invalid value is supplied.
- Returns:
- the character at the specified position or DONE if the specified position is equal to getEndIndex()
- Throws:
- IllegalArgumentException- if- pis not within the bounds (inclusive) of- getBeginIndex()to- getEndIndex()
- See Also:
 
- 
currentpublic char current()Implements CharacterIterator.current() for String.- Specified by:
- currentin interface- CharacterIterator
- Returns:
- the character at the current position or DONE if the current position is off the end of the text.
- See Also:
 
- 
nextpublic char next()Implements CharacterIterator.next() for String.- Specified by:
- nextin interface- CharacterIterator
- Returns:
- the character at the new position or DONE if the new position is off the end of the text range.
- See Also:
 
- 
previouspublic char previous()Implements CharacterIterator.previous() for String.- Specified by:
- previousin interface- CharacterIterator
- Returns:
- the character at the new position or DONE if the current position is equal to getBeginIndex().
- See Also:
 
- 
getBeginIndexpublic int getBeginIndex()Implements CharacterIterator.getBeginIndex() for String.- Specified by:
- getBeginIndexin interface- CharacterIterator
- Returns:
- the index at which the text begins.
- See Also:
 
- 
getEndIndexpublic int getEndIndex()Implements CharacterIterator.getEndIndex() for String.- Specified by:
- getEndIndexin interface- CharacterIterator
- Returns:
- the index after the last character in the text
- See Also:
 
- 
getIndexpublic int getIndex()Implements CharacterIterator.getIndex() for String.- Specified by:
- getIndexin interface- CharacterIterator
- Returns:
- the current index.
- See Also:
 
- 
equalsCompares the equality of two StringCharacterIterator objects.
- 
hashCode
- 
cloneCreates a copy of this iterator.- Specified by:
- clonein interface- CharacterIterator
- Overrides:
- clonein class- Object
- Returns:
- A copy of this
- See Also:
 
 
-