[Scala Collection] 20. Tuple

Insert image description here

In Scala, a tuple is an immutable ordered collection that can be used to store multiple elements of different types. Tuples allow multiple values ​​to be combined into a logical unit, and elements in the tuple can be accessed by index.

The length of a tuple is fixed, and once created, elements cannot be added or removed. The elements of a tuple can be of different types, for example, you can put an integer, a string, and a Boolean value in the same tuple.

1. Create tuples

In Scala, you can use parentheses ()to create tuples. The elements of a tuple are ,separated by commas, and the elements can be of different types.

Here are a few ways to create tuples:

  1. Create tuples using parentheses and commas:
val myTuple: (Int, String

Guess you like

Origin blog.csdn.net/m0_47256162/article/details/132159889