What Are Tuples?
Tuples are similar to lists but can contain multiple data types. They allow grouping of heterogeneous elements into a single value.
Creating a Tuple
|
|
Note:
The Scala compiler infers the data types of each element automatically:
1985
is anInt
"clown"
is aString
'c'
is aChar
Accessing Tuple Elements
To retrieve elements from a tuple, use ._
followed by the index (starting at 1).
|
|
Important: Unlike lists or arrays (which use zero-based indexing), tuples in Scala are one-based indexed when accessing elements.