to top
Android APIs
public final class

StringCharacterIterator

extends Object
implements CharacterIterator
java.lang.Object
   ↳ java.text.StringCharacterIterator

Class Overview

An implementation of CharacterIterator for strings.

Summary

[Expand]
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.
[Expand]
Inherited Methods
From class java.lang.Object
From interface java.text.CharacterIterator

Public Constructors

public StringCharacterIterator (String value)

Added in API level 1

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 the source string to iterate over.

public StringCharacterIterator (String value, int location)

Added in API level 1

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 the source string to iterate over.
location the current index.
Throws
IllegalArgumentException if location is negative or greater than the length of the source string.

public StringCharacterIterator (String value, int start, int end, int location)

Added in API level 1

Constructs a new StringCharacterIterator on the specified string with the begin, end and current index set to the specified values.

Parameters
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.
Throws
IllegalArgumentException if start < 0, start > end, location < start, location > end or if end is greater than the length of value.

Public Methods

public Object clone ()

Added in API level 1

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

Returns
  • a shallow copy of this iterator.
See Also

public char current ()

Added in API level 1

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

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

public boolean equals (Object object)

Added in API level 1

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 the object to compare with this object.
Returns
  • true if the specified object is equal to this StringCharacterIterator; false otherwise.
See Also

public char first ()

Added in API level 1

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

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

public int getBeginIndex ()

Added in API level 1

Returns the begin index in the source string.

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

public int getEndIndex ()

Added in API level 1

Returns the end index in the source string.

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

public int getIndex ()

Added in API level 1

Returns the current index in the source string.

Returns
  • the current index.

public int hashCode ()

Added in API level 1

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
  • this object's hash code.

public char last ()

Added in API level 1

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

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

public char next ()

Added in API level 1

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

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

public char previous ()

Added in API level 1

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

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

public char setIndex (int location)

Added in API level 1

Sets the current index in the source string.

Parameters
location the index the current position is set to.
Returns
  • 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.

public void setText (String value)

Added in API level 1

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

Parameters
value the new source string.