innspiron
innspiron

Reputation: 163

byte array is not the same

Can anyone explain me this:

byte [] arr = "hello".getBytes();

Why

arr.equals("hello".getBytes())

or

arr==("hello".getBytes())

return false?

Upvotes: 2

Views: 165

Answers (1)

Dennis
Dennis

Reputation: 2142

Hope this one helps: http://www.java-examples.com/compare-two-java-byte-arrays-example

I think that the equals method on the byte array object only checks for the same reference and not for actual content.

Upvotes: 2

Related Questions