本人支付人民币100元,求解答。String,intern(),StringBuilder相关

求大佬解答

环境:

java8 之前版本不考虑

执行顺序

第一行 天
第二行 地
第三行 人
三行代码 每次都只执行一句代码 
即 天地人 一次只执行一个 

观察结果 求解答 为什么结果不同
能把我讲明白 直接发收款码
文章看了几篇 讲的各有各的道理
放在单个可以解释通 但是一起看 就说不通了

java 复制代码
public class InitTest {
    
    public static void main(String[] args) {
       new InitTest().testA();//第一行 天
//       new InitTest().testB();//第二行 地
//       new InitTest().testAB();//第三行 人

    }
     void testA(){
         String s = new String("helloworld");
         s.intern();
         String s2 = "helloworld";
         System.out.println(System.identityHashCode(s));
         System.out.println(System.identityHashCode(s.intern()));
         System.out.println(System.identityHashCode(s2));
         System.out.println(s == s2);//
     }
    void testB(){
        String s3 = new String("hello")+new String("world");
        s3.intern();
        String s4 = "helloworld";
        System.out.println(System.identityHashCode(s3));
        System.out.println(System.identityHashCode(s3.intern()));
        System.out.println(System.identityHashCode(s4));
        System.out.println(s3 == s4);//
    }
    void testAB(){
        String s = new String("helloworld");
        s.intern();
        String s2 = "helloworld";
        System.out.println(System.identityHashCode(s));
        System.out.println(System.identityHashCode(s.intern()));
        System.out.println(System.identityHashCode(s2));
        System.out.println(s == s2);//
    
        String s3 = new String("hello")+new String("world");
        s3.intern();
        String s4 = "helloworld";
        System.out.println(System.identityHashCode(s3));
        System.out.println(System.identityHashCode(s3.intern()));
        System.out.println(System.identityHashCode(s4));
        System.out.println(s3 == s4);//
    }
    
}
相关推荐
白拾5 分钟前
使用Conda管理python环境的指南
开发语言·python·conda
从0至131 分钟前
力扣刷题 | 两数之和
c语言·开发语言
总裁余(余登武)31 分钟前
算法竞赛(Python)-万变中的不变“随机算法”
开发语言·python·算法
NormalConfidence_Man32 分钟前
C++新特性汇总
开发语言·c++
一个闪现必杀技38 分钟前
Python练习2
开发语言·python
小比卡丘1 小时前
C语言进阶版第17课—自定义类型:联合和枚举
android·java·c语言
有梦想的咕噜1 小时前
target_link_libraries()
开发语言
xmh-sxh-13141 小时前
java 数据存储方式
java
liu_chunhai1 小时前
设计模式(3)builder
java·开发语言·设计模式
姜学迁1 小时前
Rust-枚举
开发语言·后端·rust