Scala SortedSet equals()方法及示例

Scala SortedSet equals()方法及示例

equals()方法是用来检查两个SortedSets是否有相同的元素。

方法定义:def equals(that: Any):Boolean

返回类型。如果两个SortedSets的元素相同,则返回真,否则返回假。

例子 #1:

// Scala program of equals()
// method
import scala.collection.immutable.SortedSet 
  
// Creating object 
object GfG 
{ 
  
    // Main method 
    def main(args:Array[String]) 
    { 
      
        // Creating SortedSets 
        val s1 = SortedSet("geeks", "for", "cs") 
        val s2 = SortedSet("cs", "for", "geeks") 
          
        // Applying equals method 
        val result = s1.equals(s2) 
          
        // Displays output 
        println(result) 
      
    } 
} 

输出。

true

例子#2。

// Scala program of equals()
// method
import scala.collection.immutable.SortedSet 
  
// Creating object 
object GfG 
{ 
  
    // Main method 
    def main(args:Array[String]) 
    { 
      
        // Creating SortedSets 
        val s1 = SortedSet(11, 10, 2019) 
        val s2 = SortedSet(9, 10, 2018) 
          
        // Applying equals method 
        val result = s1.equals(s2) 
          
        // Displays output 
        println(result) 
      
    } 
} 

输出。

false

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程