Scala Queue equals() 方法与示例
equals()方法用于检查两个队列是否由相同顺序的相同元素组成。
Method Definition: def equals(o: Any): Boolean
Return Type: It returns true if both the queues are same or else returns false.
示例 #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 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)
}
}
输出:
Queue_1: Queue(1, 3, 2, 7, 6, 5)
Queue_2: Queue(1, 3, 2, 7, 6, 5)
Queue_1 = Queue_2: true
示例 #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 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)
}
}
输出:
Queue_1: Queue(1, 3, 2, 7, 6, 5)
Queue_2: Queue(5, 3, 2, 7, 6, 1)
Queue_1 = Queue_2: false