大家看一下 ,,每个输出语句输出什么:
- public class StringDemo1 {
- public static void main(String[] args) {
- String s1=new String("hello");
- String s2=new String("hello");
- System.out.println("1:\t"+s1==s2);//false
- System.out.println("2:\t"+s1.equals(s2));//true
-
- String s3=new String("hello");
- String s4="hello";
- System.out.println("3:\t"+s3==s4);//true
- System.out.println("4:\t"+s3.equals(s4));
-
- String s5="hello";
- String s6="hello";
- System.out.println("5:\t"+s5==s6);
- System.out.println("6:\t"+s5.equals(s6));
-
-
- String s11="hello";
- String s22="world";
- String s33="helloworld";
-
- System.out.println(s33==s11+s22);
- System.out.println(s33.equals(s11+s22));
- System.out.println(s33=="hello"+"world");
- System.out.println(s33.equals("hello"+"world"));
-
- }
- }
复制代码
.
.
.
.
.
.
.
.结果:
false
2: true
false
4: true
false
6: true
false
true
true
true
里面还有个疑惑 不知道为啥 ==的输出语句 不会输出其他内容 |
|