# FormattedValue

Added in [API level 31](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Summary: [Methods](https://developer.android.com/reference/android/icu/text/FormattedValue#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/android/icu/text/FormattedValue#inhmethods)  

# FormattedValue

*** ** * ** ***

[Kotlin](https://developer.android.com/reference/kotlin/android/icu/text/FormattedValue "View this page in Kotlin") \|Java


`
public


interface
FormattedValue
`


`


implements

`[CharSequence](https://developer.android.com/reference/java/lang/CharSequence)`


`

|---------------------------------|
| android.icu.text.FormattedValue |

|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Known indirect subclasses [DateIntervalFormat.FormattedDateInterval](https://developer.android.com/reference/android/icu/text/DateIntervalFormat.FormattedDateInterval), [FormattedNumber](https://developer.android.com/reference/android/icu/number/FormattedNumber), [FormattedNumberRange](https://developer.android.com/reference/android/icu/number/FormattedNumberRange), [ListFormatter.FormattedList](https://developer.android.com/reference/android/icu/text/ListFormatter.FormattedList), [RelativeDateTimeFormatter.FormattedRelativeDateTime](https://developer.android.com/reference/android/icu/text/RelativeDateTimeFormatter.FormattedRelativeDateTime) |---------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------| | [DateIntervalFormat.FormattedDateInterval](https://developer.android.com/reference/android/icu/text/DateIntervalFormat.FormattedDateInterval)                       | An immutable class containing the result of a date interval formatting operation. | | [FormattedNumber](https://developer.android.com/reference/android/icu/number/FormattedNumber)                                                                       | The result of a number formatting operation.                                      | | [FormattedNumberRange](https://developer.android.com/reference/android/icu/number/FormattedNumberRange)                                                             | The result of a number range formatting operation.                                | | [ListFormatter.FormattedList](https://developer.android.com/reference/android/icu/text/ListFormatter.FormattedList)                                                 | An immutable class containing the result of a list formatting operation.          | | [RelativeDateTimeFormatter.FormattedRelativeDateTime](https://developer.android.com/reference/android/icu/text/RelativeDateTimeFormatter.FormattedRelativeDateTime) | Represents the result of a formatting operation of a relative datetime.           | |

<br />

*** ** * ** ***

An abstract formatted value: a string with associated field attributes.
Many formatters format to classes implementing FormattedValue.

## Summary

|                                                                                                                                                                                                                     ### Public methods                                                                                                                                                                                                                      ||
|--------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` abstract <A extends `[Appendable](https://developer.android.com/reference/java/lang/Appendable)`> A`                   | ` `[appendTo](https://developer.android.com/reference/android/icu/text/FormattedValue#appendTo(A))`(A appendable) ` Appends the formatted string to an Appendable.                                                                                                                                                                |
| ` abstract boolean`                                                                                                      | ` `[nextPosition](https://developer.android.com/reference/android/icu/text/FormattedValue#nextPosition(android.icu.text.ConstrainedFieldPosition))`(`[ConstrainedFieldPosition](https://developer.android.com/reference/android/icu/text/ConstrainedFieldPosition)` cfpos) ` Iterates over field positions in the FormattedValue. |
| ` abstract `[AttributedCharacterIterator](https://developer.android.com/reference/java/text/AttributedCharacterIterator) | ` `[toCharacterIterator](https://developer.android.com/reference/android/icu/text/FormattedValue#toCharacterIterator())`() ` Exports the formatted number as an AttributedCharacterIterator.                                                                                                                                      |
| ` abstract `[String](https://developer.android.com/reference/java/lang/String)                                           | ` `[toString](https://developer.android.com/reference/android/icu/text/FormattedValue#toString())`() ` Returns the formatted string as a Java String.                                                                                                                                                                             |

| ### Inherited methods |
|-----------------------|---|
| From interface ` `[java.lang.CharSequence](https://developer.android.com/reference/java/lang/CharSequence)` ` |--------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` abstract char`                                                                           | ` `[charAt](https://developer.android.com/reference/java/lang/CharSequence#charAt(int))`(int index) ` Returns the `char` value at the specified index.                                                                                                                                                                                                                         | | ` default `[IntStream](https://developer.android.com/reference/java/util/stream/IntStream) | ` `[chars](https://developer.android.com/reference/java/lang/CharSequence#chars())`() ` Returns a stream of `int` zero-extending the `char` values from this sequence.                                                                                                                                                                                                         | | ` default `[IntStream](https://developer.android.com/reference/java/util/stream/IntStream) | ` `[codePoints](https://developer.android.com/reference/java/lang/CharSequence#codePoints())`() ` Returns a stream of code point values from this sequence.                                                                                                                                                                                                                    | | ` static int`                                                                              | ` `[compare](https://developer.android.com/reference/java/lang/CharSequence#compare(java.lang.CharSequence,%20java.lang.CharSequence))`(`[CharSequence](https://developer.android.com/reference/java/lang/CharSequence)` cs1, `[CharSequence](https://developer.android.com/reference/java/lang/CharSequence)` cs2) ` Compares two `CharSequence` instances lexicographically. | | ` default boolean`                                                                         | ` `[isEmpty](https://developer.android.com/reference/java/lang/CharSequence#isEmpty())`() ` Returns `true` if this character sequence is empty.                                                                                                                                                                                                                                | | ` abstract int`                                                                            | ` `[length](https://developer.android.com/reference/java/lang/CharSequence#length())`() ` Returns the length of this character sequence.                                                                                                                                                                                                                                       | | ` abstract `[CharSequence](https://developer.android.com/reference/java/lang/CharSequence) | ` `[subSequence](https://developer.android.com/reference/java/lang/CharSequence#subSequence(int,%20int))`(int start, int end) ` Returns a `CharSequence` that is a subsequence of this sequence.                                                                                                                                                                               | | ` abstract `[String](https://developer.android.com/reference/java/lang/String)             | ` `[toString](https://developer.android.com/reference/java/lang/CharSequence#toString())`() ` Returns a string containing the characters in this sequence in the same order as this sequence.                                                                                                                                                                                  | ||

## Public methods

### appendTo

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

```
public abstract A appendTo (A appendable)
```

Appends the formatted string to an Appendable.


If an IOException occurs when appending to the Appendable, an unchecked
[ICUUncheckedIOException](https://developer.android.com/reference/android/icu/util/ICUUncheckedIOException) is thrown instead.

<br />

|                                   Parameters                                   ||
|--------------|------------------------------------------------------------------|
| `appendable` | `A`: The Appendable to which to append the string output. <br /> |

|                    Returns                     ||
|-----|-------------------------------------------|
| `A` | The same Appendable, for chaining. <br /> |

|                                                                      Throws                                                                       ||
|-------------------------------------------------------------------------------------------------------------|--------------------------------------|
| [ICUUncheckedIOException](https://developer.android.com/reference/android/icu/util/ICUUncheckedIOException) | if the Appendable throws IOException |

### nextPosition

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

```
public abstract boolean nextPosition (ConstrainedFieldPosition cfpos)
```

Iterates over field positions in the FormattedValue. This lets you determine the position
of specific types of substrings, like a month or a decimal separator.

To loop over all field positions:

```
     ConstrainedFieldPosition cfpos = new ConstrainedFieldPosition();
     while (fmtval.nextPosition(cfpos)) {
         // handle the field position; get information from cfpos
     }
 
```

<br />

<br />

|                                                                                                                                                           Parameters                                                                                                                                                            ||
|---------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `cfpos` | `ConstrainedFieldPosition`: The object used for iteration state. This can provide constraints to iterate over only one specific field; see [ConstrainedFieldPosition.constrainField](https://developer.android.com/reference/android/icu/text/ConstrainedFieldPosition#constrainField(java.text.Format.Field)). <br /> |

|                                       Returns                                       ||
|-----------|--------------------------------------------------------------------------|
| `boolean` | true if a new occurrence of the field was found; false otherwise. <br /> |

### toCharacterIterator

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

```
public abstract AttributedCharacterIterator toCharacterIterator ()
```

Exports the formatted number as an AttributedCharacterIterator.


Consider using [nextPosition(ConstrainedFieldPosition)](https://developer.android.com/reference/android/icu/text/FormattedValue#nextPosition(android.icu.text.ConstrainedFieldPosition)) if you are trying to get field information.

<br />

|                                                                                        Returns                                                                                         ||
|--------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------|
| [AttributedCharacterIterator](https://developer.android.com/reference/java/text/AttributedCharacterIterator) | An AttributedCharacterIterator containing full field information. <br /> |

### toString

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

```
public abstract String toString ()
```

Returns the formatted string as a Java String.

Consider using [appendTo(A)](https://developer.android.com/reference/android/icu/text/FormattedValue#appendTo(A)) for greater efficiency.

<br />

|                                             Returns                                              ||
|--------------------------------------------------------------------|------------------------------|
| [String](https://developer.android.com/reference/java/lang/String) | The formatted string. <br /> |