2
谁能解释我:字节数组是不一样的
byte [] arr = "hello".getBytes();
为什么
arr.equals("hello".getBytes())
或
arr==("hello".getBytes())
返回假的?
谁能解释我:字节数组是不一样的
byte [] arr = "hello".getBytes();
为什么
arr.equals("hello".getBytes())
或
arr==("hello".getBytes())
返回假的?
希望这一个帮助: http://www.java-examples.com/compare-two-java-byte-arrays-example
我认为字节数组对象的equals方法仅检查相同的参考而不是实际的内容。
'=='和'equals'比较引用,而不是内容。一般来说,可变对象的equals不考虑内容。 – 2011-12-21 09:12:08
@PeterLawrey thks 4的探索..可以使用共享链接中的所有不可变对象在java – Harinder 2011-12-21 09:37:54
不幸的是,没有全面的列表。我找到的最简单的类是实现Comparable的类。然而,该列表中有一些可变类。 (以'Buffer'结尾的任何内容):| http://docs.oracle.com/javase/7/docs/api/java/lang/Comparable.html – 2011-12-21 09:55:08