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


Scala TreeSet tail()用法及代碼示例


tail()方法用於返回一個新的TreeSet,該樹集由除第一個元素外的所有元素組成。

函數定義: def tail: TreeSet[A]

返回類型: It returns a new TreeSet that consists of all the elements except the first one.



範例1:

// Scala program of tail()  
// method  
  
// Import TreeSet 
import scala.collection.mutable._
  
// Creating object  
object GfG  
{  
  
    // Main method  
    def main(args:Array[String])  
    {  
      
        // Creating TreeSet 
        val t1 = TreeSet(1, 3, 2, 7, 6, 5)  
          
        // Print the TreeSet 
        println(t1) 
         
        // Applying tail() method   
        val result = t1.tail 
          
        // Displays output  
        println("Elements of the TreeSet except the first one: " + result) 
          
    }  
} 
輸出:
TreeSet(1, 2, 3, 5, 6, 7)
Elements of the TreeSet except the first one: TreeSet(2, 3, 5, 6, 7)

範例2:

// Scala program of tail()  
// method  
  
// Import TreeSet 
import scala.collection.mutable._
  
// Creating object  
object GfG  
{  
  
    // Main method  
    def main(args:Array[String])  
    {  
      
        // Creating TreeSet 
        val t1 = TreeSet("a", "e", "i", "o", "u")  
          
        // Print the TreeSet 
        println(t1) 
         
        // Applying tail() method   
        val result = t1.tail 
          
        // Displays output  
        println("Elements of the TreeSet except the first one: " + result) 
          
    }  
} 
輸出:
TreeSet(a, e, i, o, u)
Elements of the TreeSet except the first one: TreeSet(e, i, o, u)


相關用法


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