Creating Tuples
Bundle related values together.
What Is a Tuple?
A tuple groups a fixed number of values together, even when those values have different types.
Unlike a list, where every element shares one type, a tuple can hold an Int, a String, and a Boolean all at once.
Tuples are perfect for returning or bundling a handful of related values without writing a whole class.
Creating Your First Tuple
You build a tuple by wrapping comma-separated values in parentheses.
Here we pair a name with an age. Scala figures out the types automatically.
val person = ("Alice", 30)
println(person)All lessons in this course
- Creating Tuples
- Destructuring Tuples
- Building Ranges
- Ranges in Loops