Pair

Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)
data class Pair<out A, out 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:

import kotlin.test.*

fun main(args: Array<String>) {
//sampleStart
val (a, b) = Pair(1, "x")
println(a) // 1
println(b) // x
//sampleEnd
}

Parameters

A - type of the first value.

B - type of the second value.

Constructors

Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

<init>

Creates a new instance of Pair.

Pair(first: A, second: B)

Properties

Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

first

First value.

val first: A
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

second

Second value.

val second: B

Functions

Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

toString

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

fun toString(): String

Extension Functions

Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

toList

Converts this pair into a list.

fun <T> Pair<T, T>.toList(): List<T>

© 2010–2020 JetBrains s.r.o. and Kotlin Programming Language contributors
Licensed under the Apache License, Version 2.0.
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-pair/index.html