當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


Scala Iterator addString()用法及代碼示例


addString()方法屬於AbstractIterator類的具體值成員。它在IterableOnceOps類中定義。它用於將Scala迭代器的元素附加到String Builder。

函數定義: def addString(b:StringBuilder):StringBuilder

返回類型: It returns the String Builder to which the elements were appended.



範例1:

// Scala program of addString() 
// method 
  
// Creating object 
object GfG 
{  
  
    // Main method 
    def main(args:Array[String]) 
    { 
      
        // Creating an Iterator  
        val iter = Iterator(7, 6, 8, 1) 
          
        // Applying addString method  
        val result = iter.addString(new StringBuilder()) 
          
        // Displays output 
        println(result) 
      
    } 
}
輸出:
7681

範例2:

// Scala program of addString() 
// method 
  
// Creating object 
object GfG 
{  
  
    // Main method 
    def main(args:Array[String]) 
    { 
      
        // Creating an Iterator  
        val iter = Iterator(7.7, 6.1, 8.6, 1.1) 
          
        // Applying addString method  
        val result = iter.addString(new StringBuilder()) 
          
        // Displays output 
        println(result) 
          
    } 
}
輸出:
7.76.18.61.1


相關用法


注:本文由純淨天空篩選整理自nidhi1352singh大神的英文原創作品 Scala Iterator addString() method with example。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。