本人支付人民币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);//
    }
    
}
相关推荐
天天进步2015几秒前
Python全栈项目--校园智能宿舍管理系统
开发语言·python
CodeStats4 分钟前
从 CPU 指令到 JVM 进程:彻底讲透 Java 执行 main 方法时,类加载、主线程、栈帧入栈的完整底层逻辑
java·linux·开发语言
摇滚侠5 分钟前
Spring 零基础入门到进阶 基于注解管理 Bean 38-43
xml·java·后端·spring·intellij-idea
SamDeepThinking19 分钟前
我们当年是如何真实落地BFF的?
java·后端·架构
码语智行21 分钟前
Shapefile获取空间数据和中心点坐标
java·arcgis
caoyc21 分钟前
RAG 赛道全景扫描:ragflow 一骑绝尘、微软谷歌跟进乏力、下半场属于 Agent
java
阿正的梦工坊27 分钟前
【Rust】09-泛型、Trait 与生命周期基础
开发语言·rust·c#
屋外雨大,惊蛰出没34 分钟前
深入浅出Spring Boot
java·spring boot·ioc·aop
阿正的梦工坊1 小时前
【Rust】07-错误处理:Option、Result 与 ? 运算符
开发语言·算法·rust