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

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.

主站蜘蛛池模板: 宁武县| 军事| 巴南区| 巴林左旗| 溧水县| 东兰县| 仙游县| 南郑县| 汉沽区| 南陵县| 岐山县| 金山区| 安图县| 东山县| 湘阴县| 思南县| 犍为县| 贡嘎县| 耒阳市| 奉贤区| 会理县| 北海市| 鸡西市| 思茅市| 泗洪县| 泽库县| 克山县| 米易县| 淮南市| 揭东县| 牙克石市| 长顺县| 杨浦区| 灌南县| 客服| 红安县| 古田县| 临西县| 黄骅市| 呼伦贝尔市| 永吉县|