3
我正在使用diff方法來比較兩個字符串的字節數組,但會給出意外的結果(或者它是預期的行爲?)結果。scala Array [Byte] diff
diff()
回報true
爲(subString diff originalString)
,但返回false
爲(originalString diff subString)
。如果任何人能解釋這一點,那將是非常棒的。代碼示例&輸出如下。
代碼片段
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}")
輸出
compare subString with originalString - true
compare originalString with subString - false