How do I compare two arrays in scala?

后端 未结 5 1453
情书的邮戳
情书的邮戳 2020-12-13 01:43
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 sequen

5条回答
  •  别那么骄傲
    2020-12-13 02:12

    As of Scala 2.13, the deep equality approach doesn't work and errors out:

    val a: Array[Int] = Array(1,2,4,5)
    val b: Array[Int] = Array(1,2,4,5)
    a.deep == b.deep // error: value deep is not a member of Array[Int]
    

    sameElements still works in Scala 2.13:

    a sameElements b // true
    

提交回复
热议问题