Class Overview
StringCharacterIterator
implements the
CharacterIterator
protocol for a String
.
The StringCharacterIterator
class iterates over the
entire String
.
Summary
Public Methods |
Object
|
clone()
Creates a copy of this iterator.
|
char
|
current()
Implements CharacterIterator.current() for String.
|
boolean
|
equals(Object obj)
Compares the equality of two StringCharacterIterator objects.
|
char
|
first()
Implements CharacterIterator.first() for String.
|
int
|
getBeginIndex()
Implements CharacterIterator.getBeginIndex() for String.
|
int
|
getEndIndex()
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
|
setText(String text)
Reset this iterator to point to a new string.
|
[Expand]
Inherited Methods |
From class
java.lang.Object
Object
|
clone()
Creates and returns a copy of this object.
|
boolean
|
equals(Object obj)
Indicates whether some other object is "equal to" this one.
|
void
|
finalize()
Called by the garbage collector on an object when garbage collection
determines that there are no more references to the object.
|
final
Class<?>
|
getClass()
Returns the runtime class of this Object .
|
int
|
hashCode()
Returns a hash code value for the object.
|
final
void
|
notify()
Wakes up a single thread that is waiting on this object's
monitor.
|
final
void
|
notifyAll()
Wakes up all threads that are waiting on this object's monitor.
|
String
|
toString()
Returns a string representation of the object.
|
final
void
|
wait()
Causes the current thread to wait until another thread invokes the
notify() method or the
notifyAll() method for this object.
|
final
void
|
wait(long timeout, int nanos)
Causes the current thread to wait until another thread invokes the
notify() method or the
notifyAll() method for this object, or
some other thread interrupts the current thread, or a certain
amount of real time has elapsed.
|
final
void
|
wait(long timeout)
Causes the current thread to wait until either another thread invokes the
notify() method or the
notifyAll() method for this object, or a
specified amount of time has elapsed.
|
|
From interface
java.text.CharacterIterator
abstract
Object
|
clone()
Create a copy of this iterator
|
abstract
char
|
current()
Gets the character at the current position (as returned by getIndex()).
|
abstract
char
|
first()
Sets the position to getBeginIndex() and returns the character at that
position.
|
abstract
int
|
getBeginIndex()
Returns the start index of the text.
|
abstract
int
|
getEndIndex()
Returns the end index of the text.
|
abstract
int
|
getIndex()
Returns the current index.
|
abstract
char
|
last()
Sets the position to getEndIndex()-1 (getEndIndex() if the text is empty)
and returns the character at that position.
|
abstract
char
|
next()
Increments the iterator's index by one and returns the character
at the new index.
|
abstract
char
|
previous()
Decrements the iterator's index by one and returns the character
at the new index.
|
abstract
char
|
setIndex(int position)
Sets the position to the specified position in the text and returns that
character.
|
|
Public Constructors
public
StringCharacterIterator
(String text)
Constructs an iterator with an initial index of 0.
public
StringCharacterIterator
(String text, int pos)
Constructs an iterator with the specified initial index.
Parameters
text
| The String to be iterated over |
pos
| Initial iterator position
|
public
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.
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
|
Public Methods
public
Object
clone
()
Creates a copy of this iterator.
public
char
current
()
Implements CharacterIterator.current() for String.
Returns
- the character at the current position or DONE if the current
position is off the end of the text.
public
boolean
equals
(Object obj)
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.
public
char
first
()
Implements CharacterIterator.first() for String.
Returns
- the first character in the text, or DONE if the text is empty
public
int
getBeginIndex
()
Implements CharacterIterator.getBeginIndex() for String.
Returns
- the index at which the text begins.
public
int
getEndIndex
()
Implements CharacterIterator.getEndIndex() for String.
Returns
- the index after the last character in the text
public
int
getIndex
()
Implements CharacterIterator.getIndex() for String.
public
int
hashCode
()
Computes a hashcode for this iterator.
public
char
last
()
Implements CharacterIterator.last() for String.
Returns
- the last character in the text, or DONE if the text is empty
public
char
next
()
Implements CharacterIterator.next() for String.
Returns
- the character at the new position or DONE if the new
position is off the end of the text range.
public
char
previous
()
Implements CharacterIterator.previous() for String.
Returns
- the character at the new position or DONE if the current
position is equal to getBeginIndex().
public
char
setIndex
(int p)
Implements CharacterIterator.setIndex() for String.
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()
public
void
setText
(String text)
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 |