How do I compare two arrays in scala?

Phil H picture Phil H · Mar 22, 2011 · Viewed 39k times · Source
val a: Array[Int] = Array(1,2,4,5)
val b: Array[Int] = Array(1,2,4,5)
a==b // false

Is there a pattern-matching way to see if two arrays (or sequences) are equivalent?

Answer

Moritz picture Moritz · Mar 22, 2011

You need to change your last line to

a.deep == b.deep

to do a deep comparison of the arrays.