How do I compare two arrays in scala?

后端 未结 5 1445
情书的邮戳
情书的邮戳 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 01:56

    For best performance you should use:

    java.util.Arrays.equals(a, b)
    

    This is very fast and does not require extra object allocation. Array[T] in scala is the same as Object[] in java. Same story for primitive values like Int which is java int.

提交回复
热议问题