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

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

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

addString 方法用于将 Scala 迭代器的元素附加到 String Builder。此方法与addString()方法相同,但这里还包括开始、分隔符和结束。


示例 #1:

Scala
// Scala program of addString() method
// with a start, a separator and an
// end
 
// Creating object
object GfG
{
 
    // Main method
    def main(args:Array[String])
    {
     
        // Creating a Iterator
        val m1 = Iterator(1, 3, 4, 8)
         
        // Applying addString method
        val result = m1.addString(new StringBuilder(), "=>", "|", ".")
         
        // Displays output
        println(result)
    }
}


Scala
// Scala program of addString() method
// with a start, a separator and an
// end
 
// Creating object
object GfG
{
 
    // Main method
    def main(args:Array[String])
    {
     
        // Creating a Iterator
        val m1 = Iterator(1, 3, 3, 8)
         
        // Applying addString method
        val result = m1.addString(new StringBuilder(), "=>", "|", ".")
         
        // Displays output
        println(result)
    }
}


输出:
=>1|3|4|8.

示例 #2:

斯卡拉

// Scala program of addString() method
// with a start, a separator and an
// end
 
// Creating object
object GfG
{
 
    // Main method
    def main(args:Array[String])
    {
     
        // Creating a Iterator
        val m1 = Iterator(1, 3, 3, 8)
         
        // Applying addString method
        val result = m1.addString(new StringBuilder(), "=>", "|", ".")
         
        // Displays output
        println(result)
    }
}
输出:
=>1|3|3|8.

因此,这里的相同元素不会像地图中那样被删除。