Pair

Added in 1.1.0

public class Pair<F, S>


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
final S

Public constructors

Pair(F first, S second)

Constructor for a Pair.

Public methods

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

Convenience method for creating an appropriately typed pair.

boolean

Checks the two objects for equality by delegating to their respective equals methods.

int

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

@NonNull String

Extension functions

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.

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.

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

Returns this AndroidX Pair as a Kotlin Pair.

Public fields

first

Added in 1.1.0
public final F first

second

Added in 1.1.0
public final S second

Public constructors

Pair

Added in 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
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
@NonNull 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 equals methods.

Parameters
Object o

the 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

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

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

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 AndroidX Pair as a Kotlin Pair.