# AttributedCharacterIterator

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

# AttributedCharacterIterator

`
public


interface
AttributedCharacterIterator
`  
`


implements

`[CharacterIterator](https://developer.android.com/reference/java/text/CharacterIterator)`


`

|---------------------------------------|
| java.text.AttributedCharacterIterator |

<br />

*** ** * ** ***

An`AttributedCharacterIterator`allows iteration through both text and related attribute information.

An attribute is a key/value pair, identified by the key. No two attributes on a given character can have the same key.

The values for an attribute are immutable, or must not be mutated by clients or storage. They are always passed by reference, and not cloned.

A*run with respect to an attribute*is a maximum text range for which:

- the attribute is undefined or`null`for the entire range, or
- the attribute value is defined and has the same non-`null`value for the entire range.

A*run with respect to a set of attributes*is a maximum text range for which this condition is met for each member attribute.

When getting a run with no explicit attributes specified (i.e., calling[getRunStart()](https://developer.android.com/reference/java/text/AttributedCharacterIterator#getRunStart())and[getRunLimit()](https://developer.android.com/reference/java/text/AttributedCharacterIterator#getRunLimit())), any contiguous text segments having the same attributes (the same set of attribute/value pairs) are treated as separate runs if the attributes have been given to those text segments separately.

The returned indexes are limited to the range of the iterator.

The returned attribute information is limited to runs that contain the current character.

Attribute keys are instances of[AttributedCharacterIterator.Attribute](https://developer.android.com/reference/java/text/AttributedCharacterIterator.Attribute)and its subclasses, such as[TextAttribute](https://developer.android.com/reference/java/awt/font/TextAttribute).  
**See also:**

- [AttributedCharacterIterator.Attribute](https://developer.android.com/reference/java/text/AttributedCharacterIterator.Attribute)
- [TextAttribute](https://developer.android.com/reference/java/awt/font/TextAttribute)
- [AttributedString](https://developer.android.com/reference/java/text/AttributedString)
- [Annotation](https://developer.android.com/reference/java/text/Annotation)

## Summary

|                                                                                              ### Nested classes                                                                                              ||
|----------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` class` | [AttributedCharacterIterator.Attribute](https://developer.android.com/reference/java/text/AttributedCharacterIterator.Attribute) Defines attribute keys that are used to identify text attributes. |

|                                                                                                                                                                                                                                                ### Inherited constants                                                                                                                                                                                                                                                 |
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| From interface[java.text.CharacterIterator](https://developer.android.com/reference/java/text/CharacterIterator) |--------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | `char` | [DONE](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 methods                                                                                                                                                                                                                                                                                                                                                                                                               ||
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` abstract `[Set](https://developer.android.com/reference/java/util/Set)`<`[AttributedCharacterIterator.Attribute](https://developer.android.com/reference/java/text/AttributedCharacterIterator.Attribute)`>`                                                                       | ` `[getAllAttributeKeys](https://developer.android.com/reference/java/text/AttributedCharacterIterator#getAllAttributeKeys())`() ` Returns the keys of all attributes defined on the iterator's text range.                                                                                                                                                                                                                                                                                                                                             |
| ` abstract `[Object](https://developer.android.com/reference/java/lang/Object)                                                                                                                                                                                                       | ` `[getAttribute](https://developer.android.com/reference/java/text/AttributedCharacterIterator#getAttribute(java.text.AttributedCharacterIterator.Attribute))`(`[AttributedCharacterIterator.Attribute](https://developer.android.com/reference/java/text/AttributedCharacterIterator.Attribute)` attribute) ` Returns the value of the named`attribute`for the current character.                                                                                                                                                                     |
| ` abstract `[Map](https://developer.android.com/reference/java/util/Map)`<`[AttributedCharacterIterator.Attribute](https://developer.android.com/reference/java/text/AttributedCharacterIterator.Attribute)`, `[Object](https://developer.android.com/reference/java/lang/Object)`>` | ` `[getAttributes](https://developer.android.com/reference/java/text/AttributedCharacterIterator#getAttributes())`() ` Returns a map with the attributes defined on the current character.                                                                                                                                                                                                                                                                                                                                                              |
| ` abstract int`                                                                                                                                                                                                                                                                      | ` `[getRunLimit](https://developer.android.com/reference/java/text/AttributedCharacterIterator#getRunLimit())`() ` Returns the index of the first character following the run with respect to all attributes containing the current character.                                                                                                                                                                                                                                                                                                          |
| ` abstract int`                                                                                                                                                                                                                                                                      | ` `[getRunLimit](https://developer.android.com/reference/java/text/AttributedCharacterIterator#getRunLimit(java.text.AttributedCharacterIterator.Attribute))`(`[AttributedCharacterIterator.Attribute](https://developer.android.com/reference/java/text/AttributedCharacterIterator.Attribute)` attribute) ` Returns the index of the first character following the run with respect to the given`attribute`containing the current character.                                                                                                          |
| ` abstract int`                                                                                                                                                                                                                                                                      | ` `[getRunLimit](https://developer.android.com/reference/java/text/AttributedCharacterIterator#getRunLimit(java.util.Set<?%20extends%20java.text.AttributedCharacterIterator.Attribute>))`(`[Set](https://developer.android.com/reference/java/util/Set)`<? extends `[AttributedCharacterIterator.Attribute](https://developer.android.com/reference/java/text/AttributedCharacterIterator.Attribute)`> attributes) ` Returns the index of the first character following the run with respect to the given`attributes`containing the current character. |
| ` abstract int`                                                                                                                                                                                                                                                                      | ` `[getRunStart](https://developer.android.com/reference/java/text/AttributedCharacterIterator#getRunStart(java.text.AttributedCharacterIterator.Attribute))`(`[AttributedCharacterIterator.Attribute](https://developer.android.com/reference/java/text/AttributedCharacterIterator.Attribute)` attribute) ` Returns the index of the first character of the run with respect to the given`attribute`containing the current character.                                                                                                                 |
| ` abstract int`                                                                                                                                                                                                                                                                      | ` `[getRunStart](https://developer.android.com/reference/java/text/AttributedCharacterIterator#getRunStart(java.util.Set<?%20extends%20java.text.AttributedCharacterIterator.Attribute>))`(`[Set](https://developer.android.com/reference/java/util/Set)`<? extends `[AttributedCharacterIterator.Attribute](https://developer.android.com/reference/java/text/AttributedCharacterIterator.Attribute)`> attributes) ` Returns the index of the first character of the run with respect to the given`attributes`containing the current character.        |
| ` abstract int`                                                                                                                                                                                                                                                                      | ` `[getRunStart](https://developer.android.com/reference/java/text/AttributedCharacterIterator#getRunStart())`() ` Returns the index of the first character of the run with respect to all attributes containing the current character.                                                                                                                                                                                                                                                                                                                 |

| ### Inherited methods |
|-----------------------|---|
| From interface` `[java.text.CharacterIterator](https://developer.android.com/reference/java/text/CharacterIterator)` ` |--------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` abstract `[Object](https://developer.android.com/reference/java/lang/Object) | ` `[clone](https://developer.android.com/reference/java/text/CharacterIterator#clone())`() ` Create a copy of this iterator                                                                                      | | ` abstract char`                                                               | ` `[current](https://developer.android.com/reference/java/text/CharacterIterator#current())`() ` Gets the character at the current position (as returned by getIndex()).                                         | | ` abstract char`                                                               | ` `[first](https://developer.android.com/reference/java/text/CharacterIterator#first())`() ` Sets the position to getBeginIndex() and returns the character at that position.                                    | | ` abstract int`                                                                | ` `[getBeginIndex](https://developer.android.com/reference/java/text/CharacterIterator#getBeginIndex())`() ` Returns the start index of the text.                                                                | | ` abstract int`                                                                | ` `[getEndIndex](https://developer.android.com/reference/java/text/CharacterIterator#getEndIndex())`() ` Returns the end index of the text.                                                                      | | ` abstract int`                                                                | ` `[getIndex](https://developer.android.com/reference/java/text/CharacterIterator#getIndex())`() ` Returns the current index.                                                                                    | | ` abstract char`                                                               | ` `[last](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`                                                               | ` `[next](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`                                                               | ` `[previous](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`                                                               | ` `[setIndex](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 methods

### getAllAttributeKeys

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

```
public abstract Set<AttributedCharacterIterator.Attribute> getAllAttributeKeys ()
```

Returns the keys of all attributes defined on the iterator's text range. The set is empty if no attributes are defined.

<br />

|                                                                                                                Returns                                                                                                                ||
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------|
| [Set](https://developer.android.com/reference/java/util/Set)`<`[AttributedCharacterIterator.Attribute](https://developer.android.com/reference/java/text/AttributedCharacterIterator.Attribute)`>` | the keys of all attributes <br /> |

### getAttribute

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

```
public abstract Object getAttribute (AttributedCharacterIterator.Attribute attribute)
```

Returns the value of the named`attribute`for the current character. Returns`null`if the`attribute`is not defined.

<br />

|                                     Parameters                                     ||
|-------------|-----------------------------------------------------------------------|
| `attribute` | `AttributedCharacterIterator.Attribute`: the desired attribute <br /> |

|                                                       Returns                                                        ||
|--------------------------------------------------------------------|--------------------------------------------------|
| [Object](https://developer.android.com/reference/java/lang/Object) | the value of the named`attribute`or`null` <br /> |

### getAttributes

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

```
public abstract Map<AttributedCharacterIterator.Attribute, Object> getAttributes ()
```

Returns a map with the attributes defined on the current character.

<br />

|                                                                                                                                                                   Returns                                                                                                                                                                   ||
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------|
| [Map](https://developer.android.com/reference/java/util/Map)`<`[AttributedCharacterIterator.Attribute](https://developer.android.com/reference/java/text/AttributedCharacterIterator.Attribute)`, `[Object](https://developer.android.com/reference/java/lang/Object)`>` | a map with the attributes defined on the current character <br /> |

### getRunLimit

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

```
public abstract int getRunLimit ()
```

Returns the index of the first character following the run with respect to all attributes containing the current character.

Any contiguous text segments having the same attributes (the same set of attribute/value pairs) are treated as separate runs if the attributes have been given to those text segments separately.

<br />

|                             Returns                              ||
|-------|-----------------------------------------------------------|
| `int` | the index of the first character following the run <br /> |

### getRunLimit

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

```
public abstract int getRunLimit (AttributedCharacterIterator.Attribute attribute)
```

Returns the index of the first character following the run with respect to the given`attribute`containing the current character.

<br />

|                                     Parameters                                     ||
|-------------|-----------------------------------------------------------------------|
| `attribute` | `AttributedCharacterIterator.Attribute`: the desired attribute <br /> |

|                             Returns                              ||
|-------|-----------------------------------------------------------|
| `int` | the index of the first character following the run <br /> |

### getRunLimit

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

```
public abstract int getRunLimit (Set<? extends AttributedCharacterIterator.Attribute> attributes)
```

Returns the index of the first character following the run with respect to the given`attributes`containing the current character.

<br />

|                         Parameters                          ||
|--------------|-----------------------------------------------|
| `attributes` | `Set`: a set of the desired attributes <br /> |

|                             Returns                              ||
|-------|-----------------------------------------------------------|
| `int` | the index of the first character following the run <br /> |

### getRunStart

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

```
public abstract int getRunStart (AttributedCharacterIterator.Attribute attribute)
```

Returns the index of the first character of the run with respect to the given`attribute`containing the current character.

<br />

|                                     Parameters                                      ||
|-------------|------------------------------------------------------------------------|
| `attribute` | `AttributedCharacterIterator.Attribute`: the desired attribute. <br /> |

|                          Returns                          ||
|-------|----------------------------------------------------|
| `int` | the index of the first character of the run <br /> |

### getRunStart

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

```
public abstract int getRunStart (Set<? extends AttributedCharacterIterator.Attribute> attributes)
```

Returns the index of the first character of the run with respect to the given`attributes`containing the current character.

<br />

|                          Parameters                          ||
|--------------|------------------------------------------------|
| `attributes` | `Set`: a set of the desired attributes. <br /> |

|                          Returns                          ||
|-------|----------------------------------------------------|
| `int` | the index of the first character of the run <br /> |

### getRunStart

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

```
public abstract int getRunStart ()
```

Returns the index of the first character of the run with respect to all attributes containing the current character.

Any contiguous text segments having the same attributes (the same set of attribute/value pairs) are treated as separate runs if the attributes have been given to those text segments separately.

<br />

|                          Returns                          ||
|-------|----------------------------------------------------|
| `int` | the index of the first character of the run <br /> |