Scala Tuple 元组
定义元组
package org.onepiece.bigdata.windows import java.time.LocalDate object App { def main(args: Array[String]): Unit = { //定义元组 val tuple = (24, 3.14, "ROSE", LocalDate.now(), true) println(tuple) println(tuple._1) println(tuple._2) println(tuple._3) println(tuple._4) println(tuple._5) } }
(24,3.14,ROSE,2021-03-07,true) 24 3.14 ROSE 2021-03-07 true
方法返回元组
package org.onepiece.bigdata.windows import java.time.LocalDate object App { def main(args: Array[String]): Unit = { //定义元组 val tuple = getTuple() println(tuple) println(tuple._1) println(tuple._2) println(tuple._3) println(tuple._4) println(tuple._5) } def getTuple(): (Int, Double, String, LocalDate, Boolean) = { val i = 24 val d = 3.14D val s = "ROSE" val date = LocalDate.now() val isOK = true return (i, d, s, date, isOK) //return (24, 3.14, "ROSE", LocalDate.now(), true) } }
(24,3.14,ROSE,2021-03-07,true) 24 3.14 ROSE 2021-03-07 true

浙公网安备 33010602011771号