首页 > 技术文章 > Scala元组

noyouth 2020-04-16 17:02 原文

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")
    }

  }
}

  

推荐阅读