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 program of equals() // method // Import Queue import scala.collection.mutable. _
// Creating object object GfG
{ // Main method
def main(args : Array[String])
{
// Creating queues
val q 1 = Queue( 1 , 3 , 2 , 7 , 6 , 5 )
val q 2 = Queue( 1 , 3 , 2 , 7 , 6 , 5 )
// Print the queue
println( "Queue_1: " + q 1 )
println( "Queue_2: " + q 2 )
// Applying equals method
val result = q 1 .equals(q 2 )
// 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 program of equals() // method // Import Queue import scala.collection.mutable. _
// Creating object object GfG
{ // Main method
def main(args : Array[String])
{
// Creating queues
val q 1 = Queue( 1 , 3 , 2 , 7 , 6 , 5 )
val q 2 = Queue( 5 , 3 , 2 , 7 , 6 , 1 )
// Print the queue
println( "Queue_1: " + q 1 )
println( "Queue_2: " + q 2 )
// Applying equals method
val result = q 1 .equals(q 2 )
// 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