Skip to content

Most visited

Recently visited

navigation
Added in API level 1

StringCharacterIterator

public final class StringCharacterIterator
extends Object implements CharacterIterator

java.lang.Object
   ↳ java.text.StringCharacterIterator


An implementation of CharacterIterator for strings.

Summary

Inherited constants

From interface java.text.CharacterIterator

Public constructors

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.

Public methods

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.

Inherited methods

From class java.lang.Object
From interface java.text.CharacterIterator

Public constructors

StringCharacterIterator

Added in API level 1
StringCharacterIterator (String value)

Constructs a new 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.

Parameters
value String: the source string to iterate over.

StringCharacterIterator

Added in API level 1
StringCharacterIterator (String value, 
                int location)

Constructs a new 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.

Parameters
value String: the source string to iterate over.
location int: the current index.
Throws
IllegalArgumentException if location is negative or greater than the length of the source string.

StringCharacterIterator

Added in API level 1
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.

Parameters
value String: the source string to iterate over.
start int: the index of the first character to iterate.
end int: the index one past the last character to iterate.
location int: the current index.
Throws
IllegalArgumentException if start < 0, start > end, location < start, location > end or if end is greater than the length of value.

Public methods

clone

Added in API level 1
Object clone ()

Returns a new StringCharacterIterator with the same source string, begin, end, and current index as this iterator.

Returns
Object a shallow copy of this iterator.

See also:

current

Added in API level 1
char current ()

Returns the character at the current index in the source string.

Returns
char the current character, or DONE if the current index is past the end.

equals

Added in API level 1
boolean equals (Object object)

Compares the specified object with this 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.

Parameters
object Object: the object to compare with this object.
Returns
boolean true if the specified object is equal to this StringCharacterIterator; false otherwise.

See also:

first

Added in API level 1
char first ()

Sets the current position to the begin index and returns the character at the new position in the source string.

Returns
char the character at the begin index or DONE if the begin index is equal to the end index.

getBeginIndex

Added in API level 1
int getBeginIndex ()

Returns the begin index in the source string.

Returns
int the index of the first character of the iteration.

getEndIndex

Added in API level 1
int getEndIndex ()

Returns the end index in the source string.

Returns
int the index one past the last character of the iteration.

getIndex

Added in API level 1
int getIndex ()

Returns the current index in the source string.

Returns
int the current index.

hashCode

Added in API level 1
int hashCode ()

Returns an integer hash code for this object. By contract, any two objects for which equals(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.

Returns
int this object's hash code.

last

Added in API level 1
char last ()

Sets the current position to the end index - 1 and returns the character at the new position.

Returns
char the character before the end index or DONE if the begin index is equal to the end index.

next

Added in API level 1
char next ()

Increments the current index and returns the character at the new index.

Returns
char the character at the next index, or DONE if the next index would be past the end.

previous

Added in API level 1
char previous ()

Decrements the current index and returns the character at the new index.

Returns
char the character at the previous index, or DONE if the previous index would be past the beginning.

setIndex

Added in API level 1
char setIndex (int location)

Sets the current index in the source string.

Parameters
location int: the index the current position is set to.
Returns
char the character at the new index, or DONE if location is set to the end index.
Throws
IllegalArgumentException if location is smaller than the begin index or greater than the end index.

setText

Added in API level 1
void setText (String value)

Sets the source string to iterate over. The begin and end positions are set to the start and end of this string.

Parameters
value String: the new source string.
This site uses cookies to store your preferences for site-specific language and display options.

Hooray!

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.