📌  相关文章
📜  Scala Mutable SortedMap mkString() 方法与示例

📅  最后修改于: 2022-05-13 01:55:13.670000             🧑  作者: Mango

Scala Mutable SortedMap mkString() 方法与示例

mkString()方法用于将 SortedMap 的元素表示为字符串。

示例 #1:

// Scala program of mkString()
// method
import scala.collection.SortedMap
  
  
// Creating object
object GfG
{ 
  
    // Main method
    def main(args:Array[String])
    {
      
        // Creating SortedMap
        val m1 = SortedMap("geeks" -> 5, "for" -> 3, "cs" -> 6)
          
        // Applying mkString method 
        val result = m1.mkString
          
        // Displays output
        println(result)
    }
}
输出:
cs -> 6for -> 3geeks -> 5

示例 #2:

// Scala program of mkString()
// method
import scala.collection.SortedMap
  
  
// Creating object
object GfG
{ 
  
    // Main method
    def main(args:Array[String])
    {
      
        // Creating SortedMap
        val m1 = SortedMap("geeks" -> 5, "for" -> 3, "for" -> 3)
          
        // Applying mkString method 
        val result = m1.mkString
          
        // Displays output
        println(result)
    }
}
输出:
for -> 3geeks -> 5