Added in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Nested Classes](https://developer.android.com/reference/android/icu/text/Edits#nestedclasses) \| [Ctors](https://developer.android.com/reference/android/icu/text/Edits#pubctors) \| [Methods](https://developer.android.com/reference/android/icu/text/Edits#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/android/icu/text/Edits#inhmethods)

# Edits

*** ** * ** ***

` public final class Edits `   
` extends https://developer.android.com/reference/java/lang/Object ` ` `

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

<br />

*** ** * ** ***

Records lengths of string edits but not replacement text. Supports replacements, insertions, deletions in linear progression. Does not support moving/reordering of text.

There are two types of edits: *change edits* and *no-change edits* . Add edits to instances of this class using `https://developer.android.com/reference/android/icu/text/Edits#addReplace(int,%20int)` (for change edits) and `https://developer.android.com/reference/android/icu/text/Edits#addUnchanged(int)` (for no-change edits). Change edits are retained with full granularity, whereas adjacent no-change edits are always merged together. In no-change edits, there is a one-to-one mapping between code points in the source and destination strings.

After all edits have been added, instances of this class should be considered immutable, and an `https://developer.android.com/reference/android/icu/text/Edits.Iterator` can be used for queries.

There are four flavors of Edits.Iterator:

- `https://developer.android.com/reference/android/icu/text/Edits#getFineIterator()` retains full granularity of change edits.
- `https://developer.android.com/reference/android/icu/text/Edits#getFineChangesIterator()` retains full granularity of change edits, and when calling next() on the iterator, skips over no-change edits (unchanged regions).
- `https://developer.android.com/reference/android/icu/text/Edits#getCoarseIterator()` treats adjacent change edits as a single edit. (Adjacent no-change edits are automatically merged during the construction phase.)
- `https://developer.android.com/reference/android/icu/text/Edits#getCoarseChangesIterator()` treats adjacent change edits as a single edit, and when calling next() on the iterator, skips over no-change edits (unchanged regions).

For example, consider the string "abcßDeF", which case-folds to "abcssdef". This string has the following fine edits:

- abc \\u21e8 abc (no-change)
- ß \\u21e8 ss (change)
- D \\u21e8 d (change)
- e \\u21e8 e (no-change)
- F \\u21e8 f (change)

and the following coarse edits (note how adjacent change edits get merged together):

<!-- -->

- abc \\u21e8 abc (no-change)
- ßD \\u21e8 ssd (change)
- e \\u21e8 e (no-change)
- F \\u21e8 f (change)

The "fine changes" and "coarse changes" iterators will step through only the change edits when their `https://developer.android.com/reference/android/icu/text/Edits.Iterator#next()` methods are called. They are identical to the non-change iterators when their `https://developer.android.com/reference/android/icu/text/Edits.Iterator#findSourceIndex(int)` or `https://developer.android.com/reference/android/icu/text/Edits.Iterator#findDestinationIndex(int)` methods are used to walk through the string.

For examples of how to use this class, see the test `TestCaseMapEditsIteratorDocs` in UCharacterCaseTest.java.

## Summary

| ### Nested classes ||
|---|---|
| ` class` | `https://developer.android.com/reference/android/icu/text/Edits.Iterator` Access to the list of edits. |

| ### Public constructors ||
|---|---|
| ` https://developer.android.com/reference/android/icu/text/Edits#Edits()() ` Constructs an empty object. |

| ### Public methods ||
|---|---|
| ` void` | ` https://developer.android.com/reference/android/icu/text/Edits#addReplace(int,%20int)(int oldLength, int newLength) ` Adds a change edit: a record for a text replacement/insertion/deletion. |
| ` void` | ` https://developer.android.com/reference/android/icu/text/Edits#addUnchanged(int)(int unchangedLength) ` Adds a no-change edit: a record for an unchanged segment of text. |
| ` https://developer.android.com/reference/android/icu/text/Edits.Iterator` | ` https://developer.android.com/reference/android/icu/text/Edits#getCoarseChangesIterator()() ` Returns an Iterator for coarse-grained change edits (adjacent change edits are treated as one). |
| ` https://developer.android.com/reference/android/icu/text/Edits.Iterator` | ` https://developer.android.com/reference/android/icu/text/Edits#getCoarseIterator()() ` Returns an Iterator for coarse-grained change and no-change edits (adjacent change edits are treated as one). |
| ` https://developer.android.com/reference/android/icu/text/Edits.Iterator` | ` https://developer.android.com/reference/android/icu/text/Edits#getFineChangesIterator()() ` Returns an Iterator for fine-grained change edits (full granularity of change edits is retained). |
| ` https://developer.android.com/reference/android/icu/text/Edits.Iterator` | ` https://developer.android.com/reference/android/icu/text/Edits#getFineIterator()() ` Returns an Iterator for fine-grained change and no-change edits (full granularity of change edits is retained). |
| ` boolean` | ` https://developer.android.com/reference/android/icu/text/Edits#hasChanges()() ` |
| ` int` | ` https://developer.android.com/reference/android/icu/text/Edits#lengthDelta()() ` How much longer is the new text compared with the old text? |
| ` https://developer.android.com/reference/android/icu/text/Edits` | ` https://developer.android.com/reference/android/icu/text/Edits#mergeAndAppend(android.icu.text.Edits,%20android.icu.text.Edits)(https://developer.android.com/reference/android/icu/text/Edits ab, https://developer.android.com/reference/android/icu/text/Edits bc) ` Merges the two input Edits and appends the result to this object. |
| ` int` | ` https://developer.android.com/reference/android/icu/text/Edits#numberOfChanges()() ` |
| ` void` | ` https://developer.android.com/reference/android/icu/text/Edits#reset()() ` Resets the data but may not release memory. |

### 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*.

## Public constructors

### Edits

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

```
public Edits ()
```

Constructs an empty object.

<br />

## Public methods

### addReplace

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

```
public void addReplace (int oldLength, 
                int newLength)
```

Adds a change edit: a record for a text replacement/insertion/deletion. Normally called from inside ICU string transformation functions, not user code.

<br />

| Parameters ||
|---|---|
| `oldLength` | `int` <br /> |
| `newLength` | `int` <br /> |

### addUnchanged

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

```
public void addUnchanged (int unchangedLength)
```

Adds a no-change edit: a record for an unchanged segment of text. Normally called from inside ICU string transformation functions, not user code.

<br />

| Parameters ||
|---|---|
| `unchangedLength` | `int` <br /> |

### getCoarseChangesIterator

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

```
public Edits.Iterator getCoarseChangesIterator ()
```

Returns an Iterator for coarse-grained change edits (adjacent change edits are treated as one). Can be used to perform simple string updates. Skips no-change edits.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/icu/text/Edits.Iterator` | an Iterator that merges adjacent changes. <br /> |

### getCoarseIterator

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

```
public Edits.Iterator getCoarseIterator ()
```

Returns an Iterator for coarse-grained change and no-change edits (adjacent change edits are treated as one). Can be used to perform simple string updates. Adjacent change edits are treated as one edit.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/icu/text/Edits.Iterator` | an Iterator that merges adjacent changes. <br /> |

### getFineChangesIterator

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

```
public Edits.Iterator getFineChangesIterator ()
```

Returns an Iterator for fine-grained change edits (full granularity of change edits is retained). Can be used for modifying styled text. Skips no-change edits.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/icu/text/Edits.Iterator` | an Iterator that separates adjacent changes. <br /> |

### getFineIterator

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

```
public Edits.Iterator getFineIterator ()
```

Returns an Iterator for fine-grained change and no-change edits (full granularity of change edits is retained). Can be used for modifying styled text.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/icu/text/Edits.Iterator` | an Iterator that separates adjacent changes. <br /> |

### hasChanges

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

```
public boolean hasChanges ()
```

<br />

<br />

| Returns ||
|---|---|
| `boolean` | true if there are any change edits <br /> |

### lengthDelta

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

```
public int lengthDelta ()
```

How much longer is the new text compared with the old text?

<br />

| Returns ||
|---|---|
| `int` | new length minus old length <br /> |

### mergeAndAppend

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

```
public Edits mergeAndAppend (Edits ab, 
                Edits bc)
```

Merges the two input Edits and appends the result to this object.

Consider two string transformations (for example, normalization and case mapping) where each records Edits in addition to writing an output string.  

Edits ab reflect how substrings of input string a map to substrings of intermediate string b.  

Edits bc reflect how substrings of intermediate string b map to substrings of output string c.  

This function merges ab and bc such that the additional edits recorded in this object reflect how substrings of input string a map to substrings of output string c.

If unrelated Edits are passed in where the output string of the first has a different length than the input string of the second, then an IllegalArgumentException is thrown.

<br />

| Parameters ||
|---|---|
| `ab` | `Edits`: reflects how substrings of input string a map to substrings of intermediate string b. <br /> |
| `bc` | `Edits`: reflects how substrings of intermediate string b map to substrings of output string c. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/icu/text/Edits` | this, with the merged edits appended <br /> |

### numberOfChanges

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

```
public int numberOfChanges ()
```

<br />

<br />

| Returns ||
|---|---|
| `int` | the number of change edits <br /> |

### reset

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

```
public void reset ()
```

Resets the data but may not release memory.

<br />