# 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)

*** ** * ** ***


```
public final class LocaleListCompat
```

<br />

*** ** * ** ***

Helper for accessing features in `https://developer.android.com/reference/android/os/LocaleList.html`.

## Summary

| ### Public methods |
|---|---|
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/core/os/LocaleListCompat` | `https://developer.android.com/reference/androidx/core/os/LocaleListCompat#create(java.util.Locale...)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html Locale[] localeList)` Creates a new instance of `https://developer.android.com/reference/androidx/core/os/LocaleListCompat` from the `https://developer.android.com/reference/java/util/Locale.html` array. |
| `boolean` | `https://developer.android.com/reference/androidx/core/os/LocaleListCompat#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object.html other)` |
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/core/os/LocaleListCompat` | `https://developer.android.com/reference/androidx/core/os/LocaleListCompat#forLanguageTags(java.lang.String)(@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/String.html list)` Generates a new LocaleList with the given language tags. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/util/Locale.html` | `https://developer.android.com/reference/androidx/core/os/LocaleListCompat#get(int)(int index)` Retrieves the `https://developer.android.com/reference/java/util/Locale.html` at the specified index. |
| `static @https://developer.android.com/reference/androidx/annotation/Size(min = 1) @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/core/os/LocaleListCompat` | `https://developer.android.com/reference/androidx/core/os/LocaleListCompat#getAdjustedDefault()()` Returns the default locale list, adjusted by moving the default locale to its first position. |
| `static @https://developer.android.com/reference/androidx/annotation/Size(min = 1) @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/core/os/LocaleListCompat` | `https://developer.android.com/reference/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. |
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/core/os/LocaleListCompat` | `https://developer.android.com/reference/androidx/core/os/LocaleListCompat#getEmptyLocaleList()()` Retrieve an empty instance of `https://developer.android.com/reference/androidx/core/os/LocaleListCompat`. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/util/Locale.html` | `https://developer.android.com/reference/androidx/core/os/LocaleListCompat#getFirstMatch(java.lang.String[])(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html String[] supportedLocales)` Returns the first match in the locale list given an unordered array of supported locales in BCP 47 format. |
| `int` | `https://developer.android.com/reference/androidx/core/os/LocaleListCompat#hashCode()()` |
| `@https://developer.android.com/reference/androidx/annotation/IntRange(from = "-1") int` | `https://developer.android.com/reference/androidx/core/os/LocaleListCompat#indexOf(java.util.Locale)(@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/util/Locale.html locale)` Searches this `https://developer.android.com/reference/androidx/core/os/LocaleListCompat` for the specified `https://developer.android.com/reference/java/util/Locale.html` and returns the index of the first occurrence. |
| `boolean` | `https://developer.android.com/reference/androidx/core/os/LocaleListCompat#isEmpty()()` Returns whether the `https://developer.android.com/reference/androidx/core/os/LocaleListCompat` contains no `https://developer.android.com/reference/java/util/Locale.html` items. |
| `static boolean` | `https://developer.android.com/reference/androidx/core/os/LocaleListCompat#matchesLanguageAndScript(java.util.Locale,java.util.Locale)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/Locale.html supported, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/Locale.html desired )` Determine whether two locales are considered a match, even if they are not exactly equal. |
| `@https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) int` | `https://developer.android.com/reference/androidx/core/os/LocaleListCompat#size()()` Returns the number of `https://developer.android.com/reference/java/util/Locale.html` items in this `https://developer.android.com/reference/androidx/core/os/LocaleListCompat`. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/core/os/LocaleListCompat#toLanguageTags()()` Retrieves a String representation of the language tags in this list. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/core/os/LocaleListCompat#toString()()` |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/Object.html` | `https://developer.android.com/reference/androidx/core/os/LocaleListCompat#unwrap()()` Gets the underlying framework object. |
| `static https://developer.android.com/reference/androidx/core/os/LocaleListCompat` | `@https://developer.android.com/reference/androidx/annotation/RequiresApi(value = 24) [wrap](https://developer.android.com/reference/androidx/core/os/LocaleListCompat#wrap(java.lang.Object))(https://developer.android.com/reference/java/lang/Object.html localeList)` **This method is deprecated.** Use `https://developer.android.com/reference/androidx/core/os/LocaleListCompat#wrap(android.os.LocaleList)` <br /> |
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/core/os/LocaleListCompat` | `@https://developer.android.com/reference/androidx/annotation/RequiresApi(value = 24) https://developer.android.com/reference/androidx/core/os/LocaleListCompat#wrap(android.os.LocaleList)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/os/LocaleList.html localeList)` Creates a new instance of `https://developer.android.com/reference/androidx/core/os/LocaleListCompat` from the Locale list. |

## Public methods

### create

```
public static @NonNull LocaleListCompat create(@NonNull Locale[] localeList)
```

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

### equals

```
public boolean equals(Object other)
```

### forLanguageTags

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

```
public static @NonNull LocaleListCompat forLanguageTags(@Nullable String list)
```

Generates a new LocaleList with the given language tags.

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

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/String.html list` | The language tags to be included as a single `https://developer.android.com/reference/java/lang/String.html` separated by commas. |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/core/os/LocaleListCompat` | A new instance with the `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)

```
public @Nullable Locale get(int index)
```

Retrieves the `https://developer.android.com/reference/java/util/Locale.html` at the specified index.

| Parameters |
|---|---|
| `int index` | The position to retrieve. |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/util/Locale.html` | The `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)

```
public static @Size(min = 1) @NonNull LocaleListCompat getAdjustedDefault()
```

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)

```
public static @Size(min = 1) @NonNull LocaleListCompat getDefault()
```

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)

```
public static @NonNull LocaleListCompat getEmptyLocaleList()
```

Retrieve an empty instance of `https://developer.android.com/reference/androidx/core/os/LocaleListCompat`.

### getFirstMatch

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

```
public @Nullable Locale getFirstMatch(@NonNull String[] supportedLocales)
```

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

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/util/Locale.html` | The first `https://developer.android.com/reference/java/util/Locale.html` from this list that appears in the given array, or `null` if the `https://developer.android.com/reference/androidx/core/os/LocaleListCompat` is empty. |

### hashCode

```
public int hashCode()
```

### indexOf

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

```
public @IntRange(from = "-1") int indexOf(@Nullable Locale locale)
```

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

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/util/Locale.html locale` | The `https://developer.android.com/reference/java/util/Locale.html` to search for. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/IntRange(from = "-1") int` | The index of the first occurrence of the `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)

```
public boolean isEmpty()
```

Returns whether the `https://developer.android.com/reference/androidx/core/os/LocaleListCompat` contains no `https://developer.android.com/reference/java/util/Locale.html` items.

| Returns |
|---|---|
| `boolean` | `true` if this `https://developer.android.com/reference/androidx/core/os/LocaleListCompat` has no `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)

```
public static boolean matchesLanguageAndScript(
    @NonNull Locale supported,
    @NonNull Locale desired
)
```

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 |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/Locale.html supported` | The supported `https://developer.android.com/reference/java/util/Locale.html` to be compared. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/Locale.html desired` | The desired `https://developer.android.com/reference/java/util/Locale.html` to be compared. |

| Returns |
|---|---|
| `boolean` | True if they match, false otherwise. |

### size

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

```
public @IntRange(from = 0) int size()
```

Returns the number of `https://developer.android.com/reference/java/util/Locale.html` items in this `https://developer.android.com/reference/androidx/core/os/LocaleListCompat`.

### toLanguageTags

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

```
public @NonNull String toLanguageTags()
```

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

### toString

```
public @NonNull String toString()
```

### unwrap

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

```
public @Nullable Object unwrap()
```

Gets the underlying framework object.

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/Object.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)
public static LocaleListCompat [wrap](https://developer.android.com/reference/androidx/core/os/LocaleListCompat#wrap(java.lang.Object))(Object localeList)
```

> [!CAUTION]
> **This method is deprecated.**   
>
> Use `https://developer.android.com/reference/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)
public static @NonNull LocaleListCompat wrap(@NonNull LocaleList localeList)
```

Creates a new instance of `https://developer.android.com/reference/androidx/core/os/LocaleListCompat` from the Locale list.