# LocaleListCompat

# LocaleListCompat

Artifact:[androidx.core:core](https://developer.android.com/jetpack/androidx/releases/core)  
[View Source](https://cs.android.com/search?q=file:androidx/core/os/LocaleListCompat.java+class:androidx.core.os.LocaleListCompat)  
Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/core/os/LocaleListCompat "View this page in Java")

<br />

```
class LocaleListCompat
```

<br />

*** ** * ** ***

Helper for accessing features in[LocaleList](https://developer.android.com/reference/android/os/LocaleList.html).

## Summary

|                                                                                              ### Public functions                                                                                              |
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `java-static `[LocaleListCompat](https://developer.android.com/reference/kotlin/androidx/core/os/LocaleListCompat)                                                                                             | [create](https://developer.android.com/reference/kotlin/androidx/core/os/LocaleListCompat#create(java.util.Locale...))`(localeList: `[Array](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html)`<`[Locale](https://developer.android.com/reference/java/util/Locale.html)`!>)` Creates a new instance of[LocaleListCompat](https://developer.android.com/reference/kotlin/androidx/core/os/LocaleListCompat)from the[Locale](https://developer.android.com/reference/java/util/Locale.html)array.                                        |
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)                                                                                                                            | [equals](https://developer.android.com/reference/kotlin/androidx/core/os/LocaleListCompat#equals(java.lang.Object))`(other: `[Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html)`!)`                                                                                                                                                                                                                                                                                                                                                  |
| `java-static `[LocaleListCompat](https://developer.android.com/reference/kotlin/androidx/core/os/LocaleListCompat)                                                                                             | [forLanguageTags](https://developer.android.com/reference/kotlin/androidx/core/os/LocaleListCompat#forLanguageTags(java.lang.String))`(list: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`?)` Generates a new LocaleList with the given language tags.                                                                                                                                                                                                                                                                  |
| [Locale](https://developer.android.com/reference/java/util/Locale.html)`?`                                                                                                                                     | [get](https://developer.android.com/reference/kotlin/androidx/core/os/LocaleListCompat#get(int))`(index: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`)` Retrieves the[Locale](https://developer.android.com/reference/java/util/Locale.html)at the specified index.                                                                                                                                                                                                                                                          |
| `java-static @`[Size](https://developer.android.com/reference/kotlin/androidx/annotation/Size)`(min = 1) `[LocaleListCompat](https://developer.android.com/reference/kotlin/androidx/core/os/LocaleListCompat) | [getAdjustedDefault](https://developer.android.com/reference/kotlin/androidx/core/os/LocaleListCompat#getAdjustedDefault())`()` Returns the default locale list, adjusted by moving the default locale to its first position.                                                                                                                                                                                                                                                                                                                                 |
| `java-static @`[Size](https://developer.android.com/reference/kotlin/androidx/annotation/Size)`(min = 1) `[LocaleListCompat](https://developer.android.com/reference/kotlin/androidx/core/os/LocaleListCompat) | [getDefault](https://developer.android.com/reference/kotlin/androidx/core/os/LocaleListCompat#getDefault())`()` The result is guaranteed to include the default Locale returned by Locale.getDefault(), but not necessarily at the top of the list.                                                                                                                                                                                                                                                                                                           |
| `java-static `[LocaleListCompat](https://developer.android.com/reference/kotlin/androidx/core/os/LocaleListCompat)                                                                                             | [getEmptyLocaleList](https://developer.android.com/reference/kotlin/androidx/core/os/LocaleListCompat#getEmptyLocaleList())`()` Retrieve an empty instance of[LocaleListCompat](https://developer.android.com/reference/kotlin/androidx/core/os/LocaleListCompat).                                                                                                                                                                                                                                                                                            |
| [Locale](https://developer.android.com/reference/java/util/Locale.html)`?`                                                                                                                                     | [getFirstMatch](https://developer.android.com/reference/kotlin/androidx/core/os/LocaleListCompat#getFirstMatch(java.lang.String[]))`(supportedLocales: `[Array](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html)`<`[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`!>)` Returns the first match in the locale list given an unordered array of supported locales in BCP 47 format.                                                                                                                   |
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)                                                                                                                                    | [hashCode](https://developer.android.com/reference/kotlin/androidx/core/os/LocaleListCompat#hashCode())`()`                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| `@`[IntRange](https://developer.android.com/reference/kotlin/androidx/annotation/IntRange)`(from = "-1") `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)                          | [indexOf](https://developer.android.com/reference/kotlin/androidx/core/os/LocaleListCompat#indexOf(java.util.Locale))`(locale: `[Locale](https://developer.android.com/reference/java/util/Locale.html)`?)` Searches this[LocaleListCompat](https://developer.android.com/reference/kotlin/androidx/core/os/LocaleListCompat)for the specified[Locale](https://developer.android.com/reference/java/util/Locale.html)and returns the index of the first occurrence.                                                                                           |
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)                                                                                                                            | [isEmpty](https://developer.android.com/reference/kotlin/androidx/core/os/LocaleListCompat#isEmpty())`()` Returns whether the[LocaleListCompat](https://developer.android.com/reference/kotlin/androidx/core/os/LocaleListCompat)contains no[Locale](https://developer.android.com/reference/java/util/Locale.html)items.                                                                                                                                                                                                                                     |
| `java-static `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)                                                                                                              | `@`[RequiresApi](https://developer.android.com/reference/kotlin/androidx/annotation/RequiresApi)`(value = 21)` [matchesLanguageAndScript](https://developer.android.com/reference/kotlin/androidx/core/os/LocaleListCompat#matchesLanguageAndScript(java.util.Locale,java.util.Locale))`(supported: `[Locale](https://developer.android.com/reference/java/util/Locale.html)`, desired: `[Locale](https://developer.android.com/reference/java/util/Locale.html)`)` Determine whether two locales are considered a match, even if they are not exactly equal. |
| `@`[IntRange](https://developer.android.com/reference/kotlin/androidx/annotation/IntRange)`(from = 0) `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)                             | [size](https://developer.android.com/reference/kotlin/androidx/core/os/LocaleListCompat#size())`()` Returns the number of[Locale](https://developer.android.com/reference/java/util/Locale.html)items in this[LocaleListCompat](https://developer.android.com/reference/kotlin/androidx/core/os/LocaleListCompat).                                                                                                                                                                                                                                            |
| [String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)                                                                                                                              | [toLanguageTags](https://developer.android.com/reference/kotlin/androidx/core/os/LocaleListCompat#toLanguageTags())`()` Retrieves a String representation of the language tags in this list.                                                                                                                                                                                                                                                                                                                                                                  |
| [String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)                                                                                                                              | [toString](https://developer.android.com/reference/kotlin/androidx/core/os/LocaleListCompat#toString())`()`                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| [Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html)`?`                                                                                                                                 | [unwrap](https://developer.android.com/reference/kotlin/androidx/core/os/LocaleListCompat#unwrap())`()` Gets the underlying framework object.                                                                                                                                                                                                                                                                                                                                                                                                                 |
| `java-static `[LocaleListCompat](https://developer.android.com/reference/kotlin/androidx/core/os/LocaleListCompat)`!`                                                                                          | `@`[RequiresApi](https://developer.android.com/reference/kotlin/androidx/annotation/RequiresApi)`(value = 24)` ~~[wrap](https://developer.android.com/reference/kotlin/androidx/core/os/LocaleListCompat#wrap(java.lang.Object))~~`(localeList: `[Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html)`!)` **This function is deprecated.** Use[wrap](https://developer.android.com/reference/kotlin/androidx/core/os/LocaleListCompat#wrap(android.os.LocaleList)) <br />                                                              |
| `java-static `[LocaleListCompat](https://developer.android.com/reference/kotlin/androidx/core/os/LocaleListCompat)                                                                                             | `@`[RequiresApi](https://developer.android.com/reference/kotlin/androidx/annotation/RequiresApi)`(value = 24)` [wrap](https://developer.android.com/reference/kotlin/androidx/core/os/LocaleListCompat#wrap(android.os.LocaleList))`(localeList: `[LocaleList](https://developer.android.com/reference/android/os/LocaleList.html)`)` Creates a new instance of[LocaleListCompat](https://developer.android.com/reference/kotlin/androidx/core/os/LocaleListCompat)from the Locale list.                                                                      |

## Public functions

### create

```
java-static fun create(localeList: Array<Locale!>): LocaleListCompat
```

Creates a new instance of[LocaleListCompat](https://developer.android.com/reference/kotlin/androidx/core/os/LocaleListCompat)from the[Locale](https://developer.android.com/reference/java/util/Locale.html)array.  

### equals

```
fun equals(other: Any!): Boolean
```  

### forLanguageTags

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)  

```
java-static fun forLanguageTags(list: String?): LocaleListCompat
```

Generates a new LocaleList with the given language tags.

Note that for API \<24 only the first language tag will be used.  

|                                          Parameters                                          |
|----------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------|
| `list: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`?` | The language tags to be included as a single[String](https://developer.android.com/reference/java/lang/String.html)separated by commas. |

|                                               Returns                                                |
|------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------|
| [LocaleListCompat](https://developer.android.com/reference/kotlin/androidx/core/os/LocaleListCompat) | A new instance with the[Locale](https://developer.android.com/reference/java/util/Locale.html)items identified by the given tags. |

### get

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)  

```
fun get(index: Int): Locale?
```

Retrieves the[Locale](https://developer.android.com/reference/java/util/Locale.html)at the specified index.  

|                                      Parameters                                      |
|--------------------------------------------------------------------------------------|---------------------------|
| `index: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | The position to retrieve. |

|                                  Returns                                   |
|----------------------------------------------------------------------------|----------------------------------------------------------------------------------------------|
| [Locale](https://developer.android.com/reference/java/util/Locale.html)`?` | The[Locale](https://developer.android.com/reference/java/util/Locale.html)in the given index |

### getAdjustedDefault

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)  

```
java-static fun getAdjustedDefault(): @Size(min = 1) LocaleListCompat
```

Returns the default locale list, adjusted by moving the default locale to its first position.  

### getDefault

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)  

```
java-static fun getDefault(): @Size(min = 1) LocaleListCompat
```

The result is guaranteed to include the default Locale returned by Locale.getDefault(), but not necessarily at the top of the list. The default locale not being at the top of the list is an indication that the system has set the default locale to one of the user's other preferred locales, having concluded that the primary preference is not supported but a secondary preference is.

Note that for API \>= 24 the default LocaleList would change if Locale.setDefault() is called. This method takes that into account by always checking the output of Locale.getDefault() and recalculating the default LocaleList if needed.  

### getEmptyLocaleList

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)  

```
java-static fun getEmptyLocaleList(): LocaleListCompat
```

Retrieve an empty instance of[LocaleListCompat](https://developer.android.com/reference/kotlin/androidx/core/os/LocaleListCompat).  

### getFirstMatch

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)  

```
fun getFirstMatch(supportedLocales: Array<String!>): Locale?
```

Returns the first match in the locale list given an unordered array of supported locales in BCP 47 format.  

|                                  Returns                                   |
|----------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Locale](https://developer.android.com/reference/java/util/Locale.html)`?` | The first[Locale](https://developer.android.com/reference/java/util/Locale.html)from this list that appears in the given array, or`null`if the[LocaleListCompat](https://developer.android.com/reference/kotlin/androidx/core/os/LocaleListCompat)is empty. |

### hashCode

```
fun hashCode(): Int
```  

### indexOf

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)  

```
fun indexOf(locale: Locale?): @IntRange(from = "-1") Int
```

Searches this[LocaleListCompat](https://developer.android.com/reference/kotlin/androidx/core/os/LocaleListCompat)for the specified[Locale](https://developer.android.com/reference/java/util/Locale.html)and returns the index of the first occurrence.  

|                                      Parameters                                      |
|--------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------|
| `locale: `[Locale](https://developer.android.com/reference/java/util/Locale.html)`?` | The[Locale](https://developer.android.com/reference/java/util/Locale.html)to search for. |

|                                                                                        Returns                                                                                        |
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------|
| `@`[IntRange](https://developer.android.com/reference/kotlin/androidx/annotation/IntRange)`(from = "-1") `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | The index of the first occurrence of the[Locale](https://developer.android.com/reference/java/util/Locale.html)or`-1`if the item wasn't found |

### isEmpty

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)  

```
fun isEmpty(): Boolean
```

Returns whether the[LocaleListCompat](https://developer.android.com/reference/kotlin/androidx/core/os/LocaleListCompat)contains no[Locale](https://developer.android.com/reference/java/util/Locale.html)items.  

|                                       Returns                                       |
|-------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | `true`if this[LocaleListCompat](https://developer.android.com/reference/kotlin/androidx/core/os/LocaleListCompat)has no[Locale](https://developer.android.com/reference/java/util/Locale.html)items,`false`otherwise |

### matchesLanguageAndScript

Added in[1.9.0](https://developer.android.com/jetpack/androidx/releases/core#1.9.0)  

```
@RequiresApi(value = 21)
java-static fun matchesLanguageAndScript(supported: Locale, desired: Locale): Boolean
```

Determine whether two locales are considered a match, even if they are not exactly equal. They are considered as a match when both of their languages and scripts (explicit or inferred) are identical. This means that a user would be able to understand the content written in the supported locale even if they say they prefer the desired locale. E.g. \[zh-HK\] matches \[zh-Hant\]; \[en-US\] matches \[en-CA\].  

|                                      Parameters                                      |
|--------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------|
| `supported: `[Locale](https://developer.android.com/reference/java/util/Locale.html) | The supported[Locale](https://developer.android.com/reference/java/util/Locale.html)to be compared. |
| `desired: `[Locale](https://developer.android.com/reference/java/util/Locale.html)   | The desired[Locale](https://developer.android.com/reference/java/util/Locale.html)to be compared.   |

|                                       Returns                                       |
|-------------------------------------------------------------------------------------|--------------------------------------|
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | True if they match, false otherwise. |

### size

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)  

```
fun size(): @IntRange(from = 0) Int
```

Returns the number of[Locale](https://developer.android.com/reference/java/util/Locale.html)items in this[LocaleListCompat](https://developer.android.com/reference/kotlin/androidx/core/os/LocaleListCompat).  

### toLanguageTags

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)  

```
fun toLanguageTags(): String
```

Retrieves a String representation of the language tags in this list.  

### toString

```
fun toString(): String
```  

### unwrap

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)  

```
fun unwrap(): Any?
```

Gets the underlying framework object.  

|                                    Returns                                     |
|--------------------------------------------------------------------------------|-----------------------------------------------------------------|
| [Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html)`?` | an android.os.LocaleList object if API \>= 24 , or`null`if not. |

### wrap

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)  
Deprecated in[1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)  

```
@RequiresApi(value = 24)
java-static fun [wrap](https://developer.android.com/reference/kotlin/androidx/core/os/LocaleListCompat#wrap(java.lang.Object))(localeList: Any!): LocaleListCompat!
```
| **This function is deprecated.**   
|
Use[wrap](https://developer.android.com/reference/kotlin/androidx/core/os/LocaleListCompat#wrap(android.os.LocaleList))  

### wrap

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)  

```
@RequiresApi(value = 24)
java-static fun wrap(localeList: LocaleList): LocaleListCompat
```

Creates a new instance of[LocaleListCompat](https://developer.android.com/reference/kotlin/androidx/core/os/LocaleListCompat)from the Locale list.