Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Inherited Constants](https://developer.android.com/reference/java/text/StringCharacterIterator#inhconstants) \| [Ctors](https://developer.android.com/reference/java/text/StringCharacterIterator#pubctors) \| [Methods](https://developer.android.com/reference/java/text/StringCharacterIterator#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/java/text/StringCharacterIterator#inhmethods)

# StringCharacterIterator


`
public

final

class
StringCharacterIterator
`


`

extends https://developer.android.com/reference/java/lang/Object


`

`


implements

https://developer.android.com/reference/java/text/CharacterIterator


`

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | java.text.StringCharacterIterator |

<br />

*** ** * ** ***

`StringCharacterIterator` implements the
`CharacterIterator` protocol for a `String`.
The `StringCharacterIterator` class iterates over the
entire `String`.
**See also:**

- `https://developer.android.com/reference/java/text/CharacterIterator`

## Summary

| ### Inherited constants |
|---|
| From interface `https://developer.android.com/reference/java/text/CharacterIterator` |---|---| | `char` | `https://developer.android.com/reference/java/text/CharacterIterator#DONE` Constant that is returned when the iterator has reached either the end or the beginning of the text. | |

| ### Public constructors ||
|---|---|
| ` https://developer.android.com/reference/java/text/StringCharacterIterator#StringCharacterIterator(java.lang.String)(https://developer.android.com/reference/java/lang/String text) ` Constructs an iterator with an initial index of 0. |
| ` https://developer.android.com/reference/java/text/StringCharacterIterator#StringCharacterIterator(java.lang.String,%20int)(https://developer.android.com/reference/java/lang/String text, int pos) ` Constructs an iterator with the specified initial index. |
| ` https://developer.android.com/reference/java/text/StringCharacterIterator#StringCharacterIterator(java.lang.String,%20int,%20int,%20int)(https://developer.android.com/reference/java/lang/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. |

| ### Public methods ||
|---|---|
| ` https://developer.android.com/reference/java/lang/Object` | ` https://developer.android.com/reference/java/text/StringCharacterIterator#clone()() ` Creates a copy of this iterator. |
| ` char` | ` https://developer.android.com/reference/java/text/StringCharacterIterator#current()() ` Implements CharacterIterator.current() for String. |
| ` boolean` | ` https://developer.android.com/reference/java/text/StringCharacterIterator#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) ` Compares the equality of two StringCharacterIterator objects. |
| ` char` | ` https://developer.android.com/reference/java/text/StringCharacterIterator#first()() ` Implements CharacterIterator.first() for String. |
| ` int` | ` https://developer.android.com/reference/java/text/StringCharacterIterator#getBeginIndex()() ` Implements CharacterIterator.getBeginIndex() for String. |
| ` int` | ` https://developer.android.com/reference/java/text/StringCharacterIterator#getEndIndex()() ` Implements CharacterIterator.getEndIndex() for String. |
| ` int` | ` https://developer.android.com/reference/java/text/StringCharacterIterator#getIndex()() ` Implements CharacterIterator.getIndex() for String. |
| ` int` | ` https://developer.android.com/reference/java/text/StringCharacterIterator#hashCode()() ` Computes a hashcode for this iterator. |
| ` char` | ` https://developer.android.com/reference/java/text/StringCharacterIterator#last()() ` Implements CharacterIterator.last() for String. |
| ` char` | ` https://developer.android.com/reference/java/text/StringCharacterIterator#next()() ` Implements CharacterIterator.next() for String. |
| ` char` | ` https://developer.android.com/reference/java/text/StringCharacterIterator#previous()() ` Implements CharacterIterator.previous() for String. |
| ` char` | ` https://developer.android.com/reference/java/text/StringCharacterIterator#setIndex(int)(int p) ` Implements CharacterIterator.setIndex() for String. |
| ` void` | ` https://developer.android.com/reference/java/text/StringCharacterIterator#setText(java.lang.String)(https://developer.android.com/reference/java/lang/String text) ` Reset this iterator to point to a new string. |

| ### Inherited methods |
|---|---|
| From class ` https://developer.android.com/reference/java/lang/Object ` |---|---| | ` https://developer.android.com/reference/java/lang/Object` | ` https://developer.android.com/reference/java/lang/Object#clone()() ` Creates and returns a copy of this object. | | ` boolean` | ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) ` Indicates whether some other object is "equal to" this one. | | ` void` | ` https://developer.android.com/reference/java/lang/Object#finalize()() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. | | ` final https://developer.android.com/reference/java/lang/Class<?>` | ` https://developer.android.com/reference/java/lang/Object#getClass()() ` Returns the runtime class of this `Object`. | | ` int` | ` https://developer.android.com/reference/java/lang/Object#hashCode()() ` Returns a hash code value for the object. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#notify()() ` Wakes up a single thread that is waiting on this object's monitor. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#notifyAll()() ` Wakes up all threads that are waiting on this object's monitor. | | ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/java/lang/Object#toString()() ` Returns a string representation of the object. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(long timeoutMillis, int nanos) ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait(long)(long timeoutMillis) ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait()() ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*. | ||
| From interface ` https://developer.android.com/reference/java/text/CharacterIterator ` |---|---| | ` abstract https://developer.android.com/reference/java/lang/Object` | ` https://developer.android.com/reference/java/text/CharacterIterator#clone()() ` Create a copy of this iterator | | ` abstract char` | ` https://developer.android.com/reference/java/text/CharacterIterator#current()() ` Gets the character at the current position (as returned by getIndex()). | | ` abstract char` | ` https://developer.android.com/reference/java/text/CharacterIterator#first()() ` Sets the position to getBeginIndex() and returns the character at that position. | | ` abstract int` | ` https://developer.android.com/reference/java/text/CharacterIterator#getBeginIndex()() ` Returns the start index of the text. | | ` abstract int` | ` https://developer.android.com/reference/java/text/CharacterIterator#getEndIndex()() ` Returns the end index of the text. | | ` abstract int` | ` https://developer.android.com/reference/java/text/CharacterIterator#getIndex()() ` Returns the current index. | | ` abstract char` | ` https://developer.android.com/reference/java/text/CharacterIterator#last()() ` Sets the position to getEndIndex()-1 (getEndIndex() if the text is empty) and returns the character at that position. | | ` abstract char` | ` https://developer.android.com/reference/java/text/CharacterIterator#next()() ` Increments the iterator's index by one and returns the character at the new index. | | ` abstract char` | ` https://developer.android.com/reference/java/text/CharacterIterator#previous()() ` Decrements the iterator's index by one and returns the character at the new index. | | ` abstract char` | ` https://developer.android.com/reference/java/text/CharacterIterator#setIndex(int)(int position) ` Sets the position to the specified position in the text and returns that character. | ||

## Public constructors

### StringCharacterIterator

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public StringCharacterIterator (String text)
```

Constructs an iterator with an initial index of 0.

<br />

| Parameters ||
|---|---|
| `text` | `String`: the `String` to be iterated over <br /> |

### StringCharacterIterator

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public StringCharacterIterator (String text, 
                int pos)
```

Constructs an iterator with the specified initial index.

<br />

| Parameters ||
|---|---|
| `text` | `String`: The String to be iterated over <br /> |
| `pos` | `int`: Initial iterator position <br /> |

### StringCharacterIterator

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
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.

<br />

| Parameters ||
|---|---|
| `text` | `String`: The String to be iterated over <br /> |
| `begin` | `int`: Index of the first character <br /> |
| `end` | `int`: Index of the character following the last character <br /> |
| `pos` | `int`: Initial iterator position <br /> |

## Public methods

### clone

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public Object clone ()
```

Creates a copy of this iterator.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/Object` | A copy of this <br /> |

### current

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public char current ()
```

Implements CharacterIterator.current() for String.

<br />

| Returns ||
|---|---|
| `char` | the character at the current position or DONE if the current position is off the end of the text. <br /> |

**See also:**

- `https://developer.android.com/reference/java/text/CharacterIterator#current()`

### equals

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean equals (Object obj)
```

Compares the equality of two StringCharacterIterator objects.

<br />

| Parameters ||
|---|---|
| `obj` | `Object`: the StringCharacterIterator object to be compared with. <br /> |

| Returns ||
|---|---|
| `boolean` | true if the given obj is the same as this StringCharacterIterator object; false otherwise. <br /> |

### first

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public char first ()
```

Implements CharacterIterator.first() for String.

<br />

| Returns ||
|---|---|
| `char` | the first character in the text, or DONE if the text is empty <br /> |

**See also:**

- `https://developer.android.com/reference/java/text/CharacterIterator#first()`

### getBeginIndex

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int getBeginIndex ()
```

Implements CharacterIterator.getBeginIndex() for String.

<br />

| Returns ||
|---|---|
| `int` | the index at which the text begins. <br /> |

**See also:**

- `https://developer.android.com/reference/java/text/CharacterIterator#getBeginIndex()`

### getEndIndex

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int getEndIndex ()
```

Implements CharacterIterator.getEndIndex() for String.

<br />

| Returns ||
|---|---|
| `int` | the index after the last character in the text <br /> |

**See also:**

- `https://developer.android.com/reference/java/text/CharacterIterator#getEndIndex()`

### getIndex

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int getIndex ()
```

Implements CharacterIterator.getIndex() for String.

<br />

| Returns ||
|---|---|
| `int` | the current index. <br /> |

**See also:**

- `https://developer.android.com/reference/java/text/CharacterIterator#getIndex()`

### hashCode

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int hashCode ()
```

Computes a hashcode for this iterator.

<br />

| Returns ||
|---|---|
| `int` | A hash code <br /> |

### last

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public char last ()
```

Implements CharacterIterator.last() for String.

<br />

| Returns ||
|---|---|
| `char` | the last character in the text, or DONE if the text is empty <br /> |

**See also:**

- `https://developer.android.com/reference/java/text/CharacterIterator#last()`

### next

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public char next ()
```

Implements CharacterIterator.next() for String.

<br />

| Returns ||
|---|---|
| `char` | the character at the new position or DONE if the new position is off the end of the text range. <br /> |

**See also:**

- `https://developer.android.com/reference/java/text/CharacterIterator#next()`

### previous

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public char previous ()
```

Implements CharacterIterator.previous() for String.

<br />

| Returns ||
|---|---|
| `char` | the character at the new position or DONE if the current position is equal to getBeginIndex(). <br /> |

**See also:**

- `https://developer.android.com/reference/java/text/CharacterIterator#previous()`

### setIndex

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public char setIndex (int p)
```

Implements CharacterIterator.setIndex() for String.

<br />

| Parameters ||
|---|---|
| `p` | `int`: the position within the text. Valid values range from getBeginIndex() to getEndIndex(). An IllegalArgumentException is thrown if an invalid value is supplied. <br /> |

| Returns ||
|---|---|
| `char` | the character at the specified position or DONE if the specified position is equal to getEndIndex() <br /> |

**See also:**

- `https://developer.android.com/reference/java/text/CharacterIterator#setIndex(int)`

### setText

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
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.

<br />

| Parameters ||
|---|---|
| `text` | `String`: The String to be iterated over <br /> |