本人支付人民币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);//
    }
    
}
相关推荐
小二李几秒前
什么是依赖注入(DI)&控制反转IoC
java·开发语言
今夕资源网5 分钟前
indextts API 阅读 API 重磅升级!低延迟 + 音色管理 + 缓存全拉满 支持开源阅读小说软件,其他软件应该也通用
java·后端·spring
是宇写的啊10 分钟前
SpringIoc和Di
java·开发语言
沐雪轻挽萤12 分钟前
3. C++17新特性-带初始化的 if 和 switch 语句
开发语言·c++
xianluohuanxiang16 分钟前
2026年深度:高精度气象+新能源,从风速误差到收益偏差,行业赋能正在重构电站盈利模型
大数据·开发语言·人工智能·机器学习
lifallen16 分钟前
Paimon 与 ForSt 场景选型分析
java·大数据·flink
我登哥MVP19 分钟前
【Spring6笔记】 - 12 - 代理模式
java·spring boot·笔记·spring·代理模式·aop
froginwe1124 分钟前
SQL PRIMARY KEY(主键)
开发语言
2401_8858850427 分钟前
视频短信接口集成起来复杂吗?API接入说明
开发语言·php·音视频
潇洒畅想28 分钟前
1.2 希腊字母速查表 + 公式阅读实战
java·人工智能·python·算法·rust·云计算