java 数组 equals_java中用equals比较两个内容相同的字符数组
********************************************
你在數組上調用函數equals,比較的是c和ch的地址
改成
if(Arrays.equals(ch,c));
就可以比較c和ch的內容了
********************************************
java.sun.com上說,
The equals method for class Object implements the most discriminating possible equivalence relation on objects; that is, for any non-null reference values x and y, this method returns true if and only if x and y refer to the same object (x == y has the value true).
It doesn't perform an intelligent comparison for most classes unless the class overrides it. It has been defined in a meaningful way for most Java core classes. If it's not defined for a (user) class, it behaves the same as ==.
"If it's not defined for a (user) class, it behaves the same as =="由于你沒有重寫equals方法,所以它比較的是數組的地址,相當于是==。
另外,有問題可以去sun.java.com上找每個class的說明,也可以裝個Netbeans java版(開源的),Netbeans 直接提供每個方法的說明
望采納
總結
以上是生活随笔為你收集整理的java 数组 equals_java中用equals比较两个内容相同的字符数组的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 银行理财等于银行存款吗?有什么区别?
- 下一篇: 使用枚举完成学生类,性别的设置。