Pair

data class Pair<out A, out B>(first: A, second: B) : Serializable

Represents a generic pair of two values.

There is no meaning attached to values in this class, it can be used for any purpose. Pair exhibits value semantics, i.e. two pairs are equal if both components are equal.

An example of decomposing it into values:

Samples

import samples.*
import kotlin.test.*
fun main() { 
   //sampleStart 
   val (a, b) = Pair(1, "x")
assertPrints(a, "1")
assertPrints(b, "x") 
   //sampleEnd
}

Parameters

A

type of the first value.

B

type of the second value.

Constructors

Pair
Link copied to clipboard
fun <out A, out B> Pair(first: A, second: B)

Creates a new instance of Pair.

Functions

toString
Link copied to clipboard
open override fun toString(): String

Returns string representation of the Pair including its first and second values.

Properties

first
Link copied to clipboard
val first: A

First value.

second
Link copied to clipboard
val second: B

Second value.

Extensions

toList
Link copied to clipboard
fun <T> Pair<T, T>.toList(): List<T>

Converts this pair into a list.