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


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


toString()方法用於返回TreeSet對象的字符串表示形式。

函數定義: def toString(): String

返回類型: It returns a string representation of the TreeSet object.



範例1:

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

範例2:

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


相關用法


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