Scala Array [Byte] diff
I'm using the diff method to compare two arrays of string bytes, but it gives unexpected results (or is this expected behavior?).
diff()
returns true
for (subString diff originalString)
, but returns false
for (originalString diff subString)
. It would be great if someone can explain this. Sample code and output are shown below.
Snippet of code
val subString : Array[Byte] = "cde".getBytes("UTF-8")
val originalString : Array[Byte] = "abcdefg".getBytes("UTF-8")
println(s"compare subString with originalString - ${((subString diff originalString).isEmpty).toString}")
println(s"compare originalString with subString - ${((originalString diff subString).isEmpty).toString}")
Output
compare subString with originalString - true
compare originalString with subString - false
+3
source to share
1 answer