- Scala Programming Projects
- Mikael Valot Nicolas Jorand
- 106字
- 2021-07-23 16:25:20
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.
推薦閱讀
- Truffle Quick Start Guide
- Spring Boot 2.0 Projects
- Learning QGIS 2.0
- 物聯(lián)網(wǎng)時(shí)代
- Metasploit Penetration Testing Cookbook
- 城域網(wǎng)與廣域網(wǎng)(第2版)
- Unity Artificial Intelligence Programming
- 通信十年:擁抱互聯(lián)網(wǎng)
- 深入理解OpenStack Neutron
- 高級網(wǎng)絡(luò)技術(shù)
- 網(wǎng)絡(luò)空間全球治理觀察
- Qt5 Python GUI Programming Cookbook
- NB-IoT原理和優(yōu)化
- 智慧的物聯(lián)網(wǎng):感知中國和世界的技術(shù)
- 網(wǎng)絡(luò)是怎樣連接的