Scala元组

object TupleDemo {
  def main(args: Array[String]): Unit = {
    //元组的创建
    val tuple2 = Tuple2(1, "abc")
    val tuple3 = (true, 22, "xyz")

    //元组访问
    println(tuple3._1)
    println(tuple3.productElement(0)) //下标从0开始

    //元组遍历
    for (item <- tuple3.productIterator) {
      print(item + "	")
    }

  }
}

  

原文地址:https://www.cnblogs.com/noyouth/p/12714032.html