本人支付人民币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);//
    }
    
}
相关推荐
程序员黑豆19 分钟前
Java字符串详解
java·前端·ai编程
m0_720245011 小时前
1543.统计好三元组(简单)
开发语言·算法
EntyIU2 小时前
NFS离线部署
java
叠层归一研究院3 小时前
AGI 系统(八):符号范畴嵌入函子 — SymCat ↪ C_M107 严格化
c语言·开发语言·人工智能·算法·transformer·agi
明朝百晓生3 小时前
Deep RL learning[2026/8]
开发语言·javascript·人工智能
weixin-a153003083164 小时前
python-装饰器
开发语言·python
我的xiaodoujiao4 小时前
快速学习Python基础知识详细图文教程17--类型注解和断点调试
开发语言·python·学习·测试工具
OH_TPC5 小时前
HarmonyOS APP开发---“滤镜大师“图像处理App,需要用到这个库
java·图像处理·华为·harmonyos·鸿蒙
leoZ2316 小时前
AI 辅助开发的五道坎
开发语言·人工智能·视觉检测·bert·php·超分辨率重建·openvino
imaol16 小时前
链表 -- 环链表
java·前端·链表