Open In App

Scala Queue equals() method with example

Last Updated : 24 Oct, 2019
Comments
Improve
Suggest changes
Like Article
Like
Report
The equals() method is utilized to check if two queues consists of the same elements in the same order.
Method Definition: def equals(o: Any): Boolean Return Type: It returns true if both the queues are same or else returns false.
Example #1: Scala
// Scala program of equals() 
// method 

// Import Queue  
import scala.collection.mutable._

// Creating object 
object GfG 
{ 

    // Main method 
    def main(args:Array[String]) 
    { 
    
        // Creating queues 
        val q1 = Queue(1, 3, 2, 7, 6, 5) 
        
        val q2 = Queue(1, 3, 2, 7, 6, 5) 
        
        // Print the queue
        println("Queue_1: " + q1)
        
        println("Queue_2: " + q2)
        
        // Applying equals method 
        val result = q1.equals(q2) 
        
        // Displays output 
        print("Queue_1 = Queue_2: " + result)
    } 
} 
Output:
Queue_1: Queue(1, 3, 2, 7, 6, 5)
Queue_2: Queue(1, 3, 2, 7, 6, 5)
Queue_1 = Queue_2: true
Example #2: Scala
// Scala program of equals() 
// method 

// Import Queue  
import scala.collection.mutable._

// Creating object 
object GfG 
{ 

    // Main method 
    def main(args:Array[String]) 
    { 
    
        // Creating queues 
        val q1 = Queue(1, 3, 2, 7, 6, 5) 
        
        val q2 = Queue(5, 3, 2, 7, 6, 1) 
        
        // Print the queue
        println("Queue_1: " + q1)
        
        println("Queue_2: " + q2)
        
        // Applying equals method 
        val result = q1.equals(q2) 
        
        // Displays output 
        print("Queue_1 = Queue_2: " + result)
    } 
} 
Output:
Queue_1: Queue(1, 3, 2, 7, 6, 5)
Queue_2: Queue(5, 3, 2, 7, 6, 1)
Queue_1 = Queue_2: false

Similar Reads