How to print map in Scala

1 Answer

0 votes
object MyClass {
    def main(args: Array[String]): Unit = {
        val mp = Map("scala" -> 4, "php" -> 2, "c++" -> 7, "python" -> 3);
         
        for ((k, v) <- mp) 
            printf("key: %s value: %d\n", k, v);
    }
}
   
   
   
   
/*
run:
   
key: scala value: 4
key: php value: 2
key: c++ value: 7
key: python value: 3
   
*/

 



answered Jun 2, 2021 by avibootz

Related questions

3 answers 109 views
1 answer 118 views
1 answer 95 views
3 answers 134 views
1 answer 91 views
3 answers 248 views
...