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

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

带有分隔符的 Scala Iterator addString() 方法和示例

此方法与addString()方法相同,但在这里我们甚至可以在 Iterator 的所有元素之间包含分隔符

示例 #1:

// Scala program of addString()
// method along with separator
  
// Creating object
object GfG
{ 
  
    // Main method
    def main(args:Array[String])
    {
      
        // Creating an Iterator 
        val iter = Iterator(11, 12, 13, 14)
          
        // Applying addString method
        // with a separator
        val result = iter.addString(new StringBuilder(), "#")
          
        // Displays output
        println(result)
      
    }
}
输出:
11#12#13#14

示例 #2:

// Scala program of addString()
// method along with separator
  
// Creating object
object GfG
{ 
  
    // Main method
    def main(args:Array[String])
    {
      
        // Creating an Iterator 
        val iter = Iterator(5, 6, 9)
          
        // Applying addString method
        // with a separator
        val result = iter.addString(new StringBuilder(), "*")
          
        // Displays output
        println(result)
      
    }
}
输出:
5*6*9