Tuples (pairs, triples and so on) are useful when we need a lightweight mechanism of  data together, for example, to return several values from a function.

h3. Tuple types and literals

There are 22 tuple classes named {{Tuple0}} through {{Tuple21}}. {{Tuple0}} (also called [Unit|Functions#Unit]) has zero type parameters, {{Tuple1}} has one parameter, and so on. The type parameters determine types of tuple components. For example, {{Tuple2}} is defined as follows:
{jet}
class Tuple2<out T1, out T2>(
  val _1 : T1,
  val _2 : T2
)
{jet}

We can use shorthand syntax for tuple types and values
{jet}
val intStrPair : #(Int, String) = #(1, "") // same as 'Tuple2<Int, String>(1, "")'
{jet}

One can access tuples' components either by [pattern matching|Pattern matching#Tuple patterns]:
{jet}
when (x) {
  is #(null, *) => throw NullPointerException()
  is #(val a, val b) => print(a, b)
}
{jet}
or by generic accessors {{\_1}}, {{\_2}} etc:
{jet}
print("left = ${pair._1}, right = ${pair._2}")
{jet}

To make accessors more readable, one can use [labeled tuples|#Labeled tuples].

h3. Labeled tuples

One can define a tuple type with _labels_ for its components:
{jet}
val point : #(x : Int, y : Int)
{jet}
Such a tuple can be accessed by those labels:
{jet}
print("x = ${point.x}, y = ${point.y}")
{jet}

We can even create tuples with named components, where order does not matter any more:
{jet}
val point : #(x : Int, y : Int) = #(y = 10, x = 5)
{jet}

{note:title=Labeled tuples are not implemented yet}See the corresponding [issue|http://youtrack.jetbrains.com/issue/KT-1433].{note}

h3. What's next

* [Type casts]