# AlphabeticIndex.ImmutableIndex

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

# ImmutableIndex

*** ** * ** ***

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

```
class ImmutableIndex<V : Any!> : MutableIterable<AlphabeticIndex.Bucket<V>!>
```

|---|----------------------------------------------------------------------------------------------------------------------------------------------------|
| [kotlin.Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)                                                                     ||
| ↳ | [android.icu.text.AlphabeticIndex.ImmutableIndex](https://developer.android.com/reference/kotlin/android/icu/text/AlphabeticIndex.ImmutableIndex#) |

Immutable, thread-safe version of [AlphabeticIndex](https://developer.android.com/reference/kotlin/android/icu/text/AlphabeticIndex). This class provides thread-safe methods for bucketing, and random access to buckets and their properties, but does not offer adding records to the index.

## Summary

|                                                                                                                                                                                                                                                                                        Public methods                                                                                                                                                                                                                                                                                        ||
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [AlphabeticIndex.Bucket](https://developer.android.com/reference/kotlin/android/icu/text/AlphabeticIndex.Bucket)\<V\>!                                                                                                                    | [getBucket](https://developer.android.com/reference/kotlin/android/icu/text/AlphabeticIndex.ImmutableIndex#getBucket(kotlin.Int))`(`index:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`)` Returns the index-th bucket.                                                                                           |
| [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)                                                                                                                                                                | [getBucketCount](https://developer.android.com/reference/kotlin/android/icu/text/AlphabeticIndex.ImmutableIndex#getBucketCount())`()` Returns the number of index buckets and labels, including underflow/inflow/overflow.                                                                                                                        |
| [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)                                                                                                                                                                | [getBucketIndex](https://developer.android.com/reference/kotlin/android/icu/text/AlphabeticIndex.ImmutableIndex#getBucketIndex(kotlin.CharSequence))`(`name:` `[CharSequence](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-char-sequence/index.html)!`)` Finds the index bucket for the given name and returns the number of that bucket. |
| [MutableIterator](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-mutable-iterator/index.html)\<[AlphabeticIndex.Bucket](https://developer.android.com/reference/kotlin/android/icu/text/AlphabeticIndex.Bucket)\<V\>!\> | [iterator](https://developer.android.com/reference/kotlin/android/icu/text/AlphabeticIndex.ImmutableIndex#iterator())`()` Returns an iterator over elements of type `T`.                                                                                                                                                                          |

## Public methods

### getBucket

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

```
fun getBucket(index: Int): AlphabeticIndex.Bucket<V>!
```

Returns the index-th bucket. Returns null if the index is out of range.

|                                             Parameters                                             ||
|---------|-------------------------------------------------------------------------------------------|
| `index` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html): bucket number |

|                                                                  Return                                                                   ||
|----------------------------------------------------------------------------------------------------------------------|---------------------|
| [AlphabeticIndex.Bucket](https://developer.android.com/reference/kotlin/android/icu/text/AlphabeticIndex.Bucket)<V>! | the index-th bucket |

### getBucketCount

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

```
fun getBucketCount(): Int
```

Returns the number of index buckets and labels, including underflow/inflow/overflow.

|                                                 Return                                                  ||
|----------------------------------------------------------------------------|-----------------------------|
| [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html) | the number of index buckets |

### getBucketIndex

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

```
fun getBucketIndex(name: CharSequence!): Int
```

Finds the index bucket for the given name and returns the number of that bucket. Use [getBucket(int)](https://developer.android.com/reference/kotlin/android/icu/text/AlphabeticIndex.ImmutableIndex#getBucket(kotlin.Int)) to get the bucket's properties.

|                                                                      Parameters                                                                      ||
|--------|----------------------------------------------------------------------------------------------------------------------------------------------|
| `name` | [CharSequence](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-char-sequence/index.html)!: the string to be sorted into an index bucket |

|                                                   Return                                                   ||
|----------------------------------------------------------------------------|--------------------------------|
| [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html) | the bucket number for the name |

### iterator

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

```
fun iterator(): MutableIterator<AlphabeticIndex.Bucket<V>!>
```

Returns an iterator over elements of type `T`.

|                                                                                                                       Return                                                                                                                        ||
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------|
| [MutableIterator](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-mutable-iterator/index.html)<[AlphabeticIndex.Bucket](https://developer.android.com/reference/kotlin/android/icu/text/AlphabeticIndex.Bucket)<V>!> | an Iterator. |