Scala SortedSet size()方法及示例

Scala SortedSet size()方法及示例

size() 方法用于查找SortedSet中的元素数量。

方法定义:def size:Int

返回类型。返回SortedSet中的元素数量。

例子 #1:

// Scala program of size() 
// 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 size method 
        val result = s1.size
          
        // Display output
        println(result)
    } 
} 

输出。

5

例子#2。

// Scala program of size() 
// method 
import scala.collection.immutable.SortedSet
  
// Creating object 
object GfG 
{ 
  
    // Main method 
    def main(args:Array[String]) 
    { 
        // Creating a SortedSet 
        val s1 = SortedSet(1, 0) 
          
        // Applying size method 
        val result = s1.size
          
        // Display output
        println(result)
    } 
} 

输出。

2

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程