Java String字符串常量池问题

第一个是false而第二个是true,不太理解

        String s1 = new String("hello");
        String intern1 = s1.intern();
        String s2 = "hello";
        System.out.println(s1 == s2);
        String s3 = new String("hello") + new String("hello");
        String intern3 = s3.intern();
        String s4 = "hellohello";
        System.out.println(s3 == s4);

http://www.cnblogs.com/justcooooode/p/7603381.html 参考这个,你的问题上面有

//常量池如果没有"hello"值就在常量池中创建,同时在堆中创建s1对象
String s1 = new String("hello");
//把s1的值放入常量池
String intern1 = s1.intern();  
/**s2对象指向常量池中的"hello",
 *同理如果常量池中没有这个值就会把这个字面量放入常量池中
 */
String s2 = "hello";                    
System.out.println(s1 == s2);

/**用加号拼接字符串的操作,你如果把class文件发编译之后看,
 *里边使用stringbuilder的append方法拼接的,拼接之后指向了
 *一个新的内存地址
 */
String s3 = new String("hello") + new String("hello");
//把s3的值放入常量池中,这个时候s3引用的是常量池中的值,s3并没有用new在队中创建对象
String intern3 = s3.intern();                                        
String s4 = "hellohello";
System.out.println(s3 == s4);