美文网首页
Scala学习第十一节:元组 Tuple3

Scala学习第十一节:元组 Tuple3

作者: 牛马风情 | 来源:发表于2017-04-25 23:28 被阅读0次

    创建元组

    scala> val t = (1, "hello", Console)
    t: (Int, String, Console.type) = (1,hello,scala.Console$@47b530e0)
    
    scala> val t = new Tuple3(1, "hello", Console)
    t: (Int, String, Console.type) = (1,hello,scala.Console$@47b530e0)
    
    

    获取元组中的数据

    scala> t._1+t._2
    res13: String = 1hello
    
    

    遍历元组

    scala> t.productIterator.foreach(i=>println(i))
    1
    hello
    scala.Console$@47b530e0
    

    转化成String

    scala> t.toString()
    res15: String = (1,hello,scala.Console$@47b530e0)
    
    

    相关文章

      网友评论

          本文标题:Scala学习第十一节:元组 Tuple3

          本文链接:https://www.haomeiwen.com/subject/njvbzttx.html