注意,我们平常使用的字符串的比较都是使用equals进行的
-
1、String str1=new String("apple");
String str2=new String("apple");
现在有两个Boolean型表达式:
①str1==str2;
②str1.equals(str2);
-
2、上述例子的正确值是
①false
②true
-
3、结果解析:
==比较的是两个对象的地址
equals比较的是两个对象的内容
注意,我们平常使用的字符串的比较都是使用equals进行的
1、String str1=new String("apple");
String str2=new String("apple");
现在有两个Boolean型表达式:
①str1==str2;
②str1.equals(str2);
2、上述例子的正确值是
①false
②true
3、结果解析:
==比较的是两个对象的地址
equals比较的是两个对象的内容