How to print tuple in Scala

2 Answers

0 votes
object MyClass {
    def main(args: Array[String]): Unit = {
        val t = (4, 9, 2, 8, 7)
           
        println(t);
        
        t.productIterator.foreach{i =>println(i)}
    }
}
     
     
     
     
/*
run:
     
(4,9,2,8,7)
4
9
2
8
7
     
*/

 



answered Jun 3, 2021 by avibootz
0 votes
object MyClass {
    def main(args: Array[String]): Unit = {
        val t = (4, 9, 2, 8, 7, "scala")
           
        println(t);
        
        t.productIterator.foreach(println)
    }
}
     
     
     
     
/*
run:
     
(4,9,2,8,7,scala)
4
9
2
8
7
scala
     
*/

 



answered Jun 3, 2021 by avibootz
...