本人支付人民币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);//
    }
    
}
相关推荐
不光头强1 天前
手写tomcat
java·tomcat
寻见9031 天前
救命!Spring Boot 凭什么火?从道法术器讲透,新手也能一键上手
java·spring boot·java ee
jinanmichael1 天前
【SQL】掌握SQL查询技巧:数据分组与排序
java·jvm·sql
彭于晏Yan1 天前
SpringBoot如何调用节假日API
java·spring boot·后端
jianfeng_zhu1 天前
用java解决空心金字塔的问题
java·开发语言·python
寻见9031 天前
告别只会 CRUD!Spring 核心原理吃透,这一篇就够了(Java 程序员必藏)
java·后端·spring
Moe4881 天前
基于 AOP 与 Redisson 的分布式锁实现:自动加锁、解锁与 SpEL 参数解析
java·后端·架构
敲代码的嘎仔1 天前
Java后端开发——Redis面试题汇总
java·开发语言·redis·学习·缓存·面试·职场和发展
啦啦啦_99991 天前
4. AI面试题之 Prompt
java·prompt
YmaxU1 天前
SpringAIAlibaba学习使用 ---核心API、RAG、Tool Calling
java·学习·spring·ai