# Pair

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

*** ** * ** ***


```
public class Pair<F, S>
```

<br />

*** ** * ** ***

Container to ease passing around a tuple of two objects. This object provides a sensible implementation of equals(), returning true if equals() is true on each of the contained objects.

## Summary

| ### Public fields |
|---|---|
| `final F` | `https://developer.android.com/reference/androidx/core/util/Pair#first()` |
| `final S` | `https://developer.android.com/reference/androidx/core/util/Pair#second()` |

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/core/util/Pair#Pair(F,S)(F first, S second)` Constructor for a Pair. |

| ### Public methods |
|---|---|
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/core/util/Pair<A, B>` | `<A, B> https://developer.android.com/reference/androidx/core/util/Pair#create(A,B)(A a, B b)` Convenience method for creating an appropriately typed pair. |
| `boolean` | `https://developer.android.com/reference/androidx/core/util/Pair#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object.html o)` Checks the two objects for equality by delegating to their respective `https://developer.android.com/reference/java/lang/Object.html#equals(java.lang.Object)` methods. |
| `int` | `https://developer.android.com/reference/androidx/core/util/Pair#hashCode()()` Compute a hash code using the hash codes of the underlying objects |
| `@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/util/Pair#toString()()` |

| ### Extension functions |
|---|---|
| `final @https://developer.android.com/reference/androidx/annotation/NonNull F` | `<F extends https://developer.android.com/reference/java/lang/Object.html, S extends https://developer.android.com/reference/java/lang/Object.html> https://developer.android.com/reference/androidx/core/util/PairKt.https://developer.android.com/reference/androidx/core/util/Pair#(androidx.core.util.Pair).component1()( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/core/util/Pair<@https://developer.android.com/reference/androidx/annotation/NonNull F, @https://developer.android.com/reference/androidx/annotation/NonNull S> receiver )` Returns the first component of the pair. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull S` | `<F extends https://developer.android.com/reference/java/lang/Object.html, S extends https://developer.android.com/reference/java/lang/Object.html> https://developer.android.com/reference/androidx/core/util/PairKt.https://developer.android.com/reference/androidx/core/util/Pair#(androidx.core.util.Pair).component2()( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/core/util/Pair<@https://developer.android.com/reference/androidx/annotation/NonNull F, @https://developer.android.com/reference/androidx/annotation/NonNull S> receiver )` Returns the second component of the pair. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-pair/index.html<@https://developer.android.com/reference/androidx/annotation/NonNull F, @https://developer.android.com/reference/androidx/annotation/NonNull S>` | `<F extends https://developer.android.com/reference/java/lang/Object.html, S extends https://developer.android.com/reference/java/lang/Object.html> https://developer.android.com/reference/androidx/core/util/PairKt.https://developer.android.com/reference/androidx/core/util/Pair#(androidx.core.util.Pair).toKotlinPair()( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/core/util/Pair<@https://developer.android.com/reference/androidx/annotation/NonNull F, @https://developer.android.com/reference/androidx/annotation/NonNull S> receiver )` Returns this `https://developer.android.com/reference/androidx/core/util/Pair` as a `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-pair/index.html`. |

## Public fields

### first

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

```
public final F first
```

### second

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

```
public final S second
```

## Public constructors

### Pair

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

```
public Pair(F first, S second)
```

Constructor for a Pair.

| Parameters |
|---|---|
| `F first` | the first object in the Pair |
| `S second` | the second object in the pair |

## Public methods

### create

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

```
public static @NonNull Pair<A, B> <A, B> create(A a, B b)
```

Convenience method for creating an appropriately typed pair.

| Parameters |
|---|---|
| `A a` | the first object in the Pair |
| `B b` | the second object in the pair |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/core/util/Pair<A, B>` | a Pair that is templatized with the types of a and b |

### equals

```
public boolean equals(Object o)
```

Checks the two objects for equality by delegating to their respective `https://developer.android.com/reference/java/lang/Object.html#equals(java.lang.Object)` methods.

| Parameters |
|---|---|
| `https://developer.android.com/reference/java/lang/Object.html o` | the `https://developer.android.com/reference/androidx/core/util/Pair` to which this one is to be checked for equality |

| Returns |
|---|---|
| `boolean` | true if the underlying objects of the Pair are both considered equal |

### hashCode

```
public int hashCode()
```

Compute a hash code using the hash codes of the underlying objects

| Returns |
|---|---|
| `int` | a hashcode of the Pair |

### toString

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

## Extension functions

### PairKt.component1

Artifact: [androidx.core:core](https://developer.android.com/jetpack/androidx/releases/core) [View Source](https://cs.android.com/search?q=file:androidx/core/util/Pair.kt+function:component1)

```
public final @NonNull F <F extends Object, S extends Object> PairKt.component1(
    @NonNull Pair<@NonNull F, @NonNull S> receiver
)
```

Returns the first component of the pair.

This method allows to use destructuring declarations when working with pairs, for example:

```
val (first, second) = myPair
```

### PairKt.component2

Artifact: [androidx.core:core](https://developer.android.com/jetpack/androidx/releases/core) [View Source](https://cs.android.com/search?q=file:androidx/core/util/Pair.kt+function:component2)

```
public final @NonNull S <F extends Object, S extends Object> PairKt.component2(
    @NonNull Pair<@NonNull F, @NonNull S> receiver
)
```

Returns the second component of the pair.

This method allows to use destructuring declarations when working with pairs, for example:

```
val (first, second) = myPair
```

### PairKt.toKotlinPair

Artifact: [androidx.core:core](https://developer.android.com/jetpack/androidx/releases/core) [View Source](https://cs.android.com/search?q=file:androidx/core/util/Pair.kt+function:toKotlinPair)

```
public final @NonNull Pair<@NonNull F, @NonNull S> <F extends Object, S extends Object> PairKt.toKotlinPair(
    @NonNull Pair<@NonNull F, @NonNull S> receiver
)
```

Returns this `https://developer.android.com/reference/androidx/core/util/Pair` as a `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-pair/index.html`.