Pair<A, B>data structure stores a pair of related values, one of typeA& another of typeB.
Pair is used to store two related (associated) values. Examples of related values that can be stored using Pair :
PersonName → PersonDOBex.-Arjun → 12/12/12Letter → NumberOfOccurrenceex.-A → 20Month → NumberOfDaysex.-Jan → 31Month → TotalExpenseex.-Feb → 25000
Creating a Pair
Creating a Pair
You can create a Pair using either the Pair constructor or the to keyword :
Pair(/* one */, /* other */)
// OR
/* one */ to /* other */
Example :
fun main() {
val pair = Pair("Jan", 31) // Pair<String, Int>
// OR
val pair1 = "Jan" to 31
println(pair) // Prints (Jan, 31)
}