scala> List(1,2,3) == List(1,2,3)
res2: Boolean = true
scala> Map(1 -> "Olle") == Map(1 -> "Olle")
res3: Boolean = true
But when trying to do the same with Array, it does not work the same. Why?
scala> Array('a','b') == Array('a','b')
res4: Boolean = false
I have used 2.8.0.RC7 and 2.8.0.Beta1-prerelease.
Because the definition of “equals” for Arrays is that they refer to the same array.
This is consistent with Java’s array equality, using
Object.Equals, so it compares references.If you want to check pairwise elements, then use
sameElementsor
deepEquals, which has been deprecated in 2.8, so instead use:There’s a good Nabble discussion on array equality.