Class java.text.StringCharacterIterator
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);
}
StringCharacterIterator(String)
Construct an iterator with an initial index of 0.
StringCharacterIterator(String, int)
Construct an iterator with the specified initial index.
StringCharacterIterator(String, int, int, int)
Construct an iterator over the given range of the given string, with the
index set at the specified position.
clone()
Create a copy of this boundary
current()
Get the character at the current position (as returned by getIndex()).
equals(Object)
Compares the equality of two StringCharacterIterator objects.
first()
Set the position to getBeginIndex() and return the character at that
position.
getBeginIndex()
Return the start index of the text.
getEndIndex()
Return the end index of the text.
getIndex()
Return the current index.
hashCode()
Compute a hashcode for this enumeration
last()
Set the position to getEndIndex() and return the
character at that position.
next()
Increment the iterator's index by one and return the character
at the new index.
previous()
Decrement the iterator's index by one and return the character
at the new index.
setIndex(int)
Set the position to specified position in the text and return that
character.
StringCharacterIterator
public StringCharacterIterator(String text)
Construct an iterator with an initial index of 0.
StringCharacterIterator
public StringCharacterIterator(String text,
int pos)
Construct an iterator with the specified initial index.
Parameters:
text - The String to be iterated over
pos - Initial iterator position
StringCharacterIterator
public StringCharacterIterator(String text,
int begin,
int end,
int pos)
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
first
public char first()
Set the position to getBeginIndex() and return the character at that
position.
last
public char last()
Set the position to getEndIndex() and return the
character at that position.
setIndex
public char setIndex(int p)
Set the position to specified position in the text and return that
character.
current
public char current()
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.
next
public char next()
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.
previous
public char previous()
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.
getBeginIndex
public int getBeginIndex()
Return the start index of the text.
Returns:
the index at which the text begins.
getEndIndex
public int getEndIndex()
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.
getIndex
public int getIndex()
Return the current index.
Returns:
the current index.
equals
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.
Overrides:
equals in class Object
hashCode
public int hashCode()
Compute a hashcode for this enumeration
Returns:
A hash code
Overrides:
hashCode in class Object
clone
public Object clone()
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
Submit a bug or feature - Version 1.1.7 of Java Platform API Specification
Java is a trademark or registered trademark of Sun Microsystems, Inc. in the US and other countries.
Copyright 1995-1998 Sun Microsystems, Inc. 901 San Antonio Road,
Palo Alto, California, 94303, U.S.A. All Rights Reserved.
Wyszukiwarka
Podobne podstrony:
java text FieldPositionjava text CollationElementIteratorjava text Formatjava text Collatorjava text ParsePositionjava text BreakIteratorjava lang Stringjava text RuleBasedCollatorjava io StringWriterjava text SimpleDateFormatjava text ChoiceFormatjava text DateFormatjava text DateFormatSymbolsjava text DecimalFormatjava io StringBufferInputStreamjava text DecimalFormatSymbolsjava text CharacterIteratorPackage java textjava text NumberFormatwięcej podobnych podstron