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


Scala mutable SortedSet dropRight()用法及代码示例


在scala可变集合中,dropRight()用于返回除最后一个‘n’元素以外的所有元素。

Method Definition: def dropRight(n:Int):SortedSet[A]

Return Type: It returns a SortedSet containing all elements except last ‘n’ elements.

范例1:

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

范例2:

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



相关用法


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