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

# UnicodeSetIterator

*** ** * ** ***

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

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

<br />

*** ** * ** ***

UnicodeSetIterator iterates over the contents of a UnicodeSet. It iterates over either code points or code point ranges. After all code points or ranges have been returned, it returns the multicharacter strings of the UnicodeSet, if any.

This class is not intended for public subclassing.

To iterate over code points and multicharacter strings, use a loop like this:

```
for (UnicodeSetIterator it = new UnicodeSetIterator(set); it.next();) {
  processString(it.getString());
}
```

To iterate over code point ranges, use a loop like this:

```
for (UnicodeSetIterator it = new UnicodeSetIterator(set); it.nextRange();) {
  if (it.codepoint != UnicodeSetIterator.IS_STRING) {
    processCodepointRange(it.codepoint, it.codepointEnd);
  } else {
    processString(it.getString());
  }
}
```

To iterate over only the strings, start with `new UnicodeSetIterator(set).skipToStrings()`.

**Warning:**For speed, UnicodeSet iteration does not check for concurrent modification. Do not alter the UnicodeSet while iterating.
**See also:**

- `https://developer.android.com/reference/android/icu/text/UnicodeSet#ranges()`
- `https://developer.android.com/reference/android/icu/text/UnicodeSet#strings()`
- `https://developer.android.com/reference/android/icu/text/UnicodeSet#iterator()`

## Summary

| ### Fields ||
|---|---|
| ` public static int` | `https://developer.android.com/reference/android/icu/text/UnicodeSetIterator#IS_STRING` Value of `codepoint` if the iterator points to a string. |
| ` public int` | `https://developer.android.com/reference/android/icu/text/UnicodeSetIterator#codepoint` Current code point, or the special value `IS_STRING`, if the iterator points to a string. |
| ` public int` | `https://developer.android.com/reference/android/icu/text/UnicodeSetIterator#codepointEnd` When iterating over ranges using `nextRange()`, `codepointEnd` contains the inclusive end of the iteration range, if `codepoint != IS_STRING`. |
| ` public https://developer.android.com/reference/java/lang/String` | `https://developer.android.com/reference/android/icu/text/UnicodeSetIterator#string` If `codepoint == IS_STRING`, then `string` points to the current string. |

| ### Public constructors ||
|---|---|
| ` https://developer.android.com/reference/android/icu/text/UnicodeSetIterator#UnicodeSetIterator()() ` Create an iterator over nothing. |
| ` https://developer.android.com/reference/android/icu/text/UnicodeSetIterator#UnicodeSetIterator(android.icu.text.UnicodeSet)(https://developer.android.com/reference/android/icu/text/UnicodeSet set) ` Create an iterator over the given set. |

| ### Public methods ||
|---|---|
| ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/android/icu/text/UnicodeSetIterator#getString()() ` Gets the current string from the iterator. |
| ` boolean` | ` https://developer.android.com/reference/android/icu/text/UnicodeSetIterator#next()() ` Returns the next element in the set, either a single code point or a string. |
| ` boolean` | ` https://developer.android.com/reference/android/icu/text/UnicodeSetIterator#nextRange()() ` Returns the next element in the set, either a code point range or a string. |
| ` void` | ` https://developer.android.com/reference/android/icu/text/UnicodeSetIterator#reset()() ` Resets this iterator to the start of the set. |
| ` void` | ` https://developer.android.com/reference/android/icu/text/UnicodeSetIterator#reset(android.icu.text.UnicodeSet)(https://developer.android.com/reference/android/icu/text/UnicodeSet uset) ` Sets this iterator to visit the elements of the given set and resets it to the start of that set. |
| ` https://developer.android.com/reference/android/icu/text/UnicodeSetIterator` | ` https://developer.android.com/reference/android/icu/text/UnicodeSetIterator#skipToStrings()() ` Skips over the remaining code points/ranges, if any. |

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

## Fields

### IS_STRING

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

```
public static int IS_STRING
```

Value of `codepoint` if the iterator points to a string. If `codepoint == IS_STRING`, then examine `string` for the current iteration result.

<br />

### codepoint

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

```
public int codepoint
```

Current code point, or the special value `IS_STRING`, if the iterator points to a string.

<br />

### codepointEnd

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

```
public int codepointEnd
```

When iterating over ranges using `nextRange()`, `codepointEnd` contains the inclusive end of the iteration range, if `codepoint != IS_STRING`. If iterating over code points using `next()`, or if `codepoint == IS_STRING`, then the value of `codepointEnd` is undefined.

<br />

### string

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

```
public String string
```

If `codepoint == IS_STRING`, then `string` points to the current string. If `codepoint != IS_STRING`, the value of `string` is undefined.

<br />

## Public constructors

### UnicodeSetIterator

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

```
public UnicodeSetIterator ()
```

Create an iterator over nothing. `next()` and `nextRange()` return false. This is a convenience constructor allowing the target to be set later.

<br />

### UnicodeSetIterator

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

```
public UnicodeSetIterator (UnicodeSet set)
```

Create an iterator over the given set.

<br />

| Parameters ||
|---|---|
| `set` | `UnicodeSet`: set to iterate over <br /> |

## Public methods

### getString

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

```
public String getString ()
```

Gets the current string from the iterator. Only use after calling next(), not nextRange().

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | <br /> |

### next

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

```
public boolean next ()
```

Returns the next element in the set, either a single code point or a string. If there are no more elements in the set, return false. If `codepoint == IS_STRING`, the value is a string in the `string` field. Otherwise the value is a single code point in the `codepoint` field.

The order of iteration is all code points in sorted order, followed by all strings sorted order. `codepointEnd` is undefined after calling this method. `string` is undefined unless `codepoint == IS_STRING`. Do not mix calls to `next()` and `nextRange()` without calling `reset()` between them. The results of doing so are undefined.

**Warning:**For speed, UnicodeSet iteration does not check for concurrent modification. Do not alter the UnicodeSet while iterating.

<br />

| Returns ||
|---|---|
| `boolean` | true if there was another element in the set and this object contains the element. <br /> |

### nextRange

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

```
public boolean nextRange ()
```

Returns the next element in the set, either a code point range or a string. If there are no more elements in the set, return false. If `codepoint == IS_STRING`, the value is a string in the `string` field. Otherwise the value is a range of one or more code points from `codepoint` to `codepointeEnd` inclusive.

The order of iteration is all code points ranges in sorted order, followed by all strings sorted order. Ranges are disjoint and non-contiguous. `string` is undefined unless `codepoint == IS_STRING`. Do not mix calls to `next()` and `nextRange()` without calling `reset()` between them. The results of doing so are undefined.

<br />

| Returns ||
|---|---|
| `boolean` | true if there was another element in the set and this object contains the element. <br /> |

### reset

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

```
public void reset ()
```

Resets this iterator to the start of the set.

<br />

### reset

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

```
public void reset (UnicodeSet uset)
```

Sets this iterator to visit the elements of the given set and resets it to the start of that set. The iterator is valid only so long as `set` is valid.

<br />

| Parameters ||
|---|---|
| `uset` | `UnicodeSet`: the set to iterate over. <br /> |

### skipToStrings

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

```
public UnicodeSetIterator skipToStrings ()
```

Skips over the remaining code points/ranges, if any. A following call to next() or nextRange() will yield a string, if there is one. No-op if next() would return false, or if it would yield a string anyway.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/icu/text/UnicodeSetIterator` | this <br /> |

**See also:**

- `https://developer.android.com/reference/android/icu/text/UnicodeSet#strings()`