📌  相关文章
📜  带有开头、分隔符和结尾的 Scala SortedMap mkString() 方法示例

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

带有开头、分隔符和结尾的 Scala SortedMap mkString() 方法示例

此方法与mkString()相同,但此处还添加了开始、分隔符和结束。

示例 #1:

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

示例 #2:

// Scala program of mkString() method
// with a start, a separator and an
// end
import scala.collection.immutable.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 -> 3|geeks -> 5--