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 Summary
Fields declared in interface java.text.CharacterIterator
DONE
-
Constructor Summary
ConstructorDescriptionConstructs 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 Summary
Modifier and TypeMethodDescriptionclone()
Creates a copy of this iterator.char
current()
Implements CharacterIterator.current() for String.boolean
Compares the equality of two StringCharacterIterator objects.char
first()
Implements CharacterIterator.first() for String.int
Implements CharacterIterator.getBeginIndex() for String.int
Implements CharacterIterator.getEndIndex() for String.int
getIndex()
Implements CharacterIterator.getIndex() for String.int
hashCode()
Computes a hashcode for this iterator.char
last()
Implements CharacterIterator.last() for String.char
next()
Implements CharacterIterator.next() for String.char
previous()
Implements CharacterIterator.previous() for String.char
setIndex
(int p) Implements CharacterIterator.setIndex() for String.void
Reset this iterator to point to a new string.
-
Constructor Details
-
StringCharacterIterator
Constructs an iterator with an initial index of 0.- Parameters:
text
- theString
to be iterated over
-
StringCharacterIterator
Constructs an iterator with the specified initial index.- Parameters:
text
- The String to be iterated overpos
- Initial iterator position- Throws:
IllegalArgumentException
- ifpos
is not within the bounds of range (inclusive) from0
to the length oftext
-
StringCharacterIterator
Constructs 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 overbegin
- Index of the first characterend
- Index of the character following the last characterpos
- Initial iterator position- Throws:
IllegalArgumentException
- ifbegin
andend
are not within the bounds of range (inclusive) from0
to the length oftext
,begin
is greater thanend
, orpos
is not within the bounds of range (inclusive) frombegin
toend
-
-
Method Details
-
setText
Reset 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
- iftext
isnull
- Since:
- 1.2
-
first
public char first()Implements CharacterIterator.first() for String.- Specified by:
first
in interfaceCharacterIterator
- Returns:
- the first character in the text, or DONE if the text is empty
- See Also:
-
last
public char last()Implements CharacterIterator.last() for String.- Specified by:
last
in interfaceCharacterIterator
- Returns:
- the last character in the text, or DONE if the text is empty
- See Also:
-
setIndex
public char setIndex(int p) Implements CharacterIterator.setIndex() for String.- Specified by:
setIndex
in interfaceCharacterIterator
- 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
- ifp
is not within the bounds (inclusive) ofgetBeginIndex()
togetEndIndex()
- See Also:
-
current
public char current()Implements CharacterIterator.current() for String.- Specified by:
current
in interfaceCharacterIterator
- Returns:
- the character at the current position or DONE if the current position is off the end of the text.
- See Also:
-
next
public char next()Implements CharacterIterator.next() for String.- Specified by:
next
in interfaceCharacterIterator
- Returns:
- the character at the new position or DONE if the new position is off the end of the text range.
- See Also:
-
previous
public char previous()Implements CharacterIterator.previous() for String.- Specified by:
previous
in interfaceCharacterIterator
- Returns:
- the character at the new position or DONE if the current position is equal to getBeginIndex().
- See Also:
-
getBeginIndex
public int getBeginIndex()Implements CharacterIterator.getBeginIndex() for String.- Specified by:
getBeginIndex
in interfaceCharacterIterator
- Returns:
- the index at which the text begins.
- See Also:
-
getEndIndex
public int getEndIndex()Implements CharacterIterator.getEndIndex() for String.- Specified by:
getEndIndex
in interfaceCharacterIterator
- Returns:
- the index after the last character in the text
- See Also:
-
getIndex
public int getIndex()Implements CharacterIterator.getIndex() for String.- Specified by:
getIndex
in interfaceCharacterIterator
- Returns:
- the current index.
- See Also:
-
equals
Compares the equality of two StringCharacterIterator objects. -
hashCode
-
clone
Creates a copy of this iterator.- Specified by:
clone
in interfaceCharacterIterator
- Overrides:
clone
in classObject
- Returns:
- A copy of this
- See Also:
-