官术网_书友最值得收藏!

Working with tuples

Type the following in the Scala Console to get more familiar with tuples. Feel free to experiment with different types and sizes of tuples:

scala> val tuple3 = (1, "hello", 2.0)
tuple3: (Int, String, Double) = (1,hello,2.0)

scala> tuple3._1
res1: Int = 1

scala> tuple3._2
res2: String = hello

scala> val (a, b, c) = tuple3

a: Int = 1
b: String = hello
c: Double = 2.0

You can create tuples of any length up to 22, and access their elements using _1, _2, and so on. You can also declare several variables in one go for each element of the tuple.

主站蜘蛛池模板: 浦江县| 平塘县| 东台市| 山东| 胶南市| 汝阳县| 登封市| 固始县| 逊克县| 昌黎县| 礼泉县| 黑河市| 开远市| 南安市| 阿拉善盟| 西吉县| 玉山县| 临西县| 明水县| 博爱县| 高雄市| 金山区| 永顺县| 禄丰县| 扶余县| 眉山市| 阳城县| 溧水县| 南平市| 吉安县| 许昌县| 武安市| 深水埗区| 大埔区| 咸阳市| 嘉义县| 弥渡县| 衡阳县| 应城市| 桐柏县| 苏尼特右旗|