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

*** ** * ** ***

Common/AllAndroid/JVMNative/C/iOSJavaScript
- Cmn

  ```
  class Preferences.Key<T : Any?>
  ```

*** ** * ** ***

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/kotlin/androidx/datastore/preferences/core/package-summary#booleanPreferencesKey(kotlin.String)`, `https://developer.android.com/reference/kotlin/androidx/datastore/preferences/core/package-summary#intPreferencesKey(kotlin.String)`, `https://developer.android.com/reference/kotlin/androidx/datastore/preferences/core/package-summary#longPreferencesKey(kotlin.String)`, `https://developer.android.com/reference/kotlin/androidx/datastore/preferences/core/package-summary#floatPreferencesKey(kotlin.String)`, `https://developer.android.com/reference/kotlin/androidx/datastore/preferences/core/package-summary#stringPreferencesKey(kotlin.String)`, `https://developer.android.com/reference/kotlin/androidx/datastore/preferences/core/package-summary#stringSetPreferencesKey(kotlin.String)`, `https://developer.android.com/reference/kotlin/androidx/datastore/preferences/core/package-summary#doublePreferencesKey(kotlin.String)`, `https://developer.android.com/reference/kotlin/androidx/datastore/preferences/core/package-summary#byteArrayPreferencesKey(kotlin.String)`.

## Summary

| ### Public functions |
|---|---|---|
| `open operator https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/datastore/preferences/core/Preferences.Key#equals(kotlin.Any)(other: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?)` | Cmn |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/datastore/preferences/core/Preferences.Key#hashCode()()` | Cmn |
| `infix https://developer.android.com/reference/kotlin/androidx/datastore/preferences/core/Preferences.Pair<T>` | `https://developer.android.com/reference/kotlin/androidx/datastore/preferences/core/Preferences.Key#to(kotlin.Any)(value: T)` Infix function to create a Preferences.Pair. | Cmn |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | `https://developer.android.com/reference/kotlin/androidx/datastore/preferences/core/Preferences.Key#toString()()` | Cmn |

| ### Public properties |
|---|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | `https://developer.android.com/reference/kotlin/androidx/datastore/preferences/core/Preferences.Key#name()` | Cmn |

| ### Extension functions |
|---|---|---|
| `https://developer.android.com/reference/kotlin/androidx/glance/action/ActionParameters.Key<T>` | `<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html> https://developer.android.com/reference/kotlin/androidx/datastore/preferences/core/Preferences.Key<T>.https://developer.android.com/reference/kotlin/androidx/datastore/preferences/core/Preferences.Key#(androidx.datastore.preferences.core.Preferences.Key).toParametersKey()()` Creates an action key from a preferences key. | android |

## Public functions

### equals

Cmn

```
open operator fun equals(other: Any?): Boolean
```

### hashCode

Cmn

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

### to

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

```
infix fun to(value: T): Preferences.Pair<T>
```

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

| Parameters |
|---|---|
| `value: T` | is the value this preferences key should point to. |

### toString

Cmn

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

## Public properties

### name

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

```
val name: String
```

## Extension functions

### Preferences.Key.toParametersKey

android Artifact: [androidx.glance:glance](https://developer.android.com/jetpack/androidx/releases/glance) [View Source](https://cs.android.com/search?q=file:androidx/glance/action/ActionParameters.kt+function:toParametersKey)

```
fun <T : Any> Preferences.Key<T>.toParametersKey(): ActionParameters.Key<T>
```

Creates an action key from a preferences key.