在 Scala Stack class
,则使用equals()方法检查两个堆栈是否由相同顺序的相同元素组成。
函数定义: def equals(o: Any): Boolean
返回类型: It returns true if both the stacks are same or else returns false.
范例1:
// Scala program of equals()
// method
// Import Stack
import scala.collection.mutable._
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Creating stacks
val s1 = Stack(1, 3, 2, 7, 6, 5)
val s2 = Stack(1, 3, 2, 7, 6, 5)
// Print the stack
println("Stack_1: " + s1)
println("Stack_2: " + s2)
// Applying equals method
val result = s1.equals(s2)
// Display output
println("Stack_1 == Stack_2: " + result)
}
}
输出:
Stack_1: Stack(1, 3, 2, 7, 6, 5) Stack_2: Stack(1, 3, 2, 7, 6, 5) Stack_1 == Stack_2: true
范例2:
// Scala program of equals()
// method
// Import Stack
import scala.collection.mutable._
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Creating stacks
val s1 = Stack(1, 3, 2, 7, 6, 5)
val s2 = Stack(7, 3, 12, 7, 6, 5)
// Print the stack
println("Stack_1: " + s1)
println("Stack_2: " + s2)
// Applying equals method
val result = s1.equals(s2)
// Display output
println("Stack_1 == Stack_2: " + result)
}
}
输出:
Stack_1: Stack(1, 3, 2, 7, 6, 5) Stack_2: Stack(7, 3, 12, 7, 6, 5) Stack_1 == Stack_2: false
相关用法
- Scala Set equals()用法及代码示例
- Scala Map equals()用法及代码示例
- Scala SortedMap equals()用法及代码示例
- Scala String equals()用法及代码示例
- Scala Queue equals()用法及代码示例
- Scala SortedSet equals()用法及代码示例
- Scala TreeSet equals()用法及代码示例
- Scala Stack last()用法及代码示例
- Scala Stack map()用法及代码示例
- Scala Stack sum()用法及代码示例
- Scala Stack top()用法及代码示例
- Scala Stack max()用法及代码示例
- Scala Stack min()用法及代码示例
- Scala Stack contains()用法及代码示例
注:本文由纯净天空筛选整理自rupesh_rao大神的英文原创作品 Scala Stack equals() method with example。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。