String s7 = "hello";
String s8 = "world";
String s9 = "helloworld";
System.out.println(s9==s7+s8);
System.out.println(s9=="hello"+"world");
为毛第一个是FALSE。求解答

解决方案 »

  1.   

    //两个引用类型进行 == 运算先比较的是内存地址,s7、s8和s9这三个都是实例的String类对象,在内存中分配的地址是不相同的,s7+s8的值虽然得到的结果为"helloworld",但是他们指向的内存地址不同,所以结果为false
    System.out.println(s9==s7+s8);
      

  2.   

    第四行比较的是地址而不是字符串的内容,所以为false