当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Scala SortedSet toBuffer()用法及代码示例


toBuffer()方法用于返回由SortedSet的所有元素组成的缓冲区。

函数定义: def toBuffer[B >: A]: Buffer[B]

返回类型: It returns a buffer consisting of all the elements of the SortedSet.



范例1:

// Scala program of toBuffer()  
// method  
import scala.collection.immutable.SortedSet  
  
// Creating object  
object GfG  
{  
  
    // Main method  
    def main(args:Array[String])  
    {  
        // Creating a SortedSet  
        val s1 = SortedSet(1, 2, 3, 4, 5)  
          
        // Applying toBuffer method  
        val result = s1.toBuffer 
          
        // Display output 
        for (elem <- result) 
            println(elem) 
              
    }  
} 
输出:
1
2
3
4
5

范例2:

// Scala program of toBuffer()  
// method  
import scala.collection.immutable.SortedSet  
  
// Creating object  
object GfG  
{  
  
    // Main method  
    def main(args:Array[String])  
    {  
        // Creating a SortedSet  
        val s1 = SortedSet(41, 12, 23, 43, 1, 72)  
          
        // Applying toBuffer method  
        val result = s1.toBuffer 
          
        // Display output 
        for (elem <- result) 
            println(elem) 
              
    }  
} 
输出:
1
12
23
41
43
72


相关用法


注:本文由纯净天空筛选整理自gopaldave大神的英文原创作品 Scala SortedSet toBuffer() method with example。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。