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 + "\t")
    }

  }
}

  

posted @ 2020-04-16 17:02  地中有山  阅读(269)  评论(0编辑  收藏  举报