public final class StringCharacterIterator extends Object implements CharacterIterator
CharacterIterator for strings.DONE| Constructor and Description |
|---|
StringCharacterIterator(String value)
Constructs a new
StringCharacterIterator on the specified string. |
StringCharacterIterator(String value,
int location)
Constructs a new
StringCharacterIterator on the specified string
with the current index set to the specified value. |
StringCharacterIterator(String value,
int start,
int end,
int location)
Constructs a new
StringCharacterIterator on the specified string
with the begin, end and current index set to the specified values. |
| Modifier and Type | Method and Description |
|---|---|
Object |
clone()
Returns a new
StringCharacterIterator with the same source
string, begin, end, and current index as this iterator. |
char |
current()
Returns the character at the current index in the source string.
|
boolean |
equals(Object object)
Compares the specified object with this
StringCharacterIterator
and indicates if they are equal. |
char |
first()
Sets the current position to the begin index and returns the character at
the new position in the source string.
|
int |
getBeginIndex()
Returns the begin index in the source string.
|
int |
getEndIndex()
Returns the end index in the source string.
|
int |
getIndex()
Returns the current index in the source string.
|
int |
hashCode()
Returns an integer hash code for this object.
|
char |
last()
Sets the current position to the end index - 1 and returns the character
at the new position.
|
char |
next()
Increments the current index and returns the character at the new index.
|
char |
previous()
Decrements the current index and returns the character at the new index.
|
char |
setIndex(int location)
Sets the current index in the source string.
|
void |
setText(String value)
Sets the source string to iterate over.
|
public StringCharacterIterator(String value)
StringCharacterIterator on the specified string.
The begin and current indices are set to the beginning of the string, the
end index is set to the length of the string.value - the source string to iterate over.public StringCharacterIterator(String value, int location)
StringCharacterIterator on the specified string
with the current index set to the specified value. The begin index is set
to the beginning of the string, the end index is set to the length of the
string.value - the source string to iterate over.location - the current index.IllegalArgumentException - if location is negative or greater than the length
of the source string.public StringCharacterIterator(String value, int start, int end, int location)
StringCharacterIterator on the specified string
with the begin, end and current index set to the specified values.value - the source string to iterate over.start - the index of the first character to iterate.end - the index one past the last character to iterate.location - the current index.IllegalArgumentException - if start < 0, start > end, location <
start, location > end or if end is greater
than the length of value.public Object clone()
StringCharacterIterator with the same source
string, begin, end, and current index as this iterator.clone in interface CharacterIteratorclone in class ObjectCloneablepublic char current()
current in interface CharacterIteratorDONE if the current index is
past the end.public boolean equals(Object object)
StringCharacterIterator
and indicates if they are equal. In order to be equal, object
must be an instance of StringCharacterIterator that iterates over
the same sequence of characters with the same index.equals in class Objectobject - the object to compare with this object.true if the specified object is equal to this
StringCharacterIterator; false otherwise.hashCode()public char first()
first in interface CharacterIteratorDONE if the begin
index is equal to the end index.public int getBeginIndex()
getBeginIndex in interface CharacterIteratorpublic int getEndIndex()
getEndIndex in interface CharacterIteratorpublic int getIndex()
getIndex in interface CharacterIteratorpublic int hashCode()
ObjectObject.equals(java.lang.Object) returns true must return
the same hash code value. This means that subclasses of Object
usually override both methods or neither method.
Note that hash values must not change over time unless information used in equals comparisons also changes.
See Writing a correct
hashCode method
if you intend implementing your own hashCode method.
hashCode in class ObjectObject.equals(java.lang.Object)public char last()
last in interface CharacterIteratorDONE if the begin
index is equal to the end index.public char next()
next in interface CharacterIteratorDONE if the next
index would be past the end.public char previous()
previous in interface CharacterIteratorDONE if the
previous index would be past the beginning.public char setIndex(int location)
setIndex in interface CharacterIteratorlocation - the index the current position is set to.DONE if
location is set to the end index.IllegalArgumentException - if location is smaller than the begin index or greater
than the end index.public void setText(String value)
value - the new source string.