# Preferences.Key

Artifact: [androidx.datastore:datastore-preferences-core](https://developer.android.com/jetpack/androidx/releases/datastore) [View Source](https://cs.android.com/search?q=file:androidx/datastore/preferences/core/Preferences.kt+class:androidx.datastore.preferences.core.Preferences.Key) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/datastore#1.0.0)

*** ** * ** ***


```
public final class Preferences.Key<T extends Object>
```

<br />

*** ** * ** ***

Key for values stored in Preferences. Type T is the type of the value associated with the Key.

T must be one of the following: Boolean, Int, Long, Float, String, Set, Double, ByteArray.

Construct Keys for your data type using: `https://developer.android.com/reference/androidx/datastore/preferences/core/package-summary#booleanPreferencesKey(kotlin.String)`, `https://developer.android.com/reference/androidx/datastore/preferences/core/package-summary#intPreferencesKey(kotlin.String)`, `https://developer.android.com/reference/androidx/datastore/preferences/core/package-summary#longPreferencesKey(kotlin.String)`, `https://developer.android.com/reference/androidx/datastore/preferences/core/package-summary#floatPreferencesKey(kotlin.String)`, `https://developer.android.com/reference/androidx/datastore/preferences/core/package-summary#stringPreferencesKey(kotlin.String)`, `https://developer.android.com/reference/androidx/datastore/preferences/core/package-summary#stringSetPreferencesKey(kotlin.String)`, `https://developer.android.com/reference/androidx/datastore/preferences/core/package-summary#doublePreferencesKey(kotlin.String)`, `https://developer.android.com/reference/androidx/datastore/preferences/core/package-summary#byteArrayPreferencesKey(kotlin.String)`.

## Summary

| ### Public methods |
|---|---|
| `boolean` | `https://developer.android.com/reference/androidx/datastore/preferences/core/Preferences.Key#equals(kotlin.Any)(https://developer.android.com/reference/java/lang/Object.html other)` |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/datastore/preferences/core/Preferences.Key#getName()()` |
| `int` | `https://developer.android.com/reference/androidx/datastore/preferences/core/Preferences.Key#hashCode()()` |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/datastore/preferences/core/Preferences.Pair<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | `https://developer.android.com/reference/androidx/datastore/preferences/core/Preferences.Key#to(kotlin.Any)(@https://developer.android.com/reference/androidx/annotation/NonNull T value)` Infix function to create a Preferences.Pair. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/datastore/preferences/core/Preferences.Key#toString()()` |

## Public methods

### equals

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

### getName

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

```
public final @NonNull String getName()
```

### hashCode

```
public int hashCode()
```

### to

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

```
public final @NonNull Preferences.Pair<@NonNull T> to(@NonNull T value)
```

Infix function to create a Preferences.Pair. This is used to support `https://developer.android.com/reference/androidx/datastore/preferences/core/package-summary#preferencesOf(kotlin.Array)` and `https://developer.android.com/reference/androidx/datastore/preferences/core/MutablePreferences#putAll(kotlin.Array)`

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull T value` | is the value this preferences key should point to. |

### toString

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