本人支付人民币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);//
    }
    
}
相关推荐
i***27951 分钟前
Spring boot 3.3.1 官方文档 中文
java·数据库·spring boot
zhengzizhe8 分钟前
LangGraph4j LangChain4j JAVA 多Agent编排详解
java·后端
embrace9919 分钟前
【C语言学习】结构体详解
android·c语言·开发语言·数据结构·学习·算法·青少年编程
重整旗鼓~20 分钟前
3.会话功能-AiServices工具类
java·语言模型·langchain
无心水21 分钟前
【Python实战进阶】4、Python字典与集合深度解析
开发语言·人工智能·python·python字典·python集合·python实战进阶·python工业化实战进阶
代码不停36 分钟前
Java单链表和哈希表题目练习
java·开发语言·散列表
Dxxyyyy38 分钟前
零基础学JAVA--Day37(坦克大战1.0)
java·开发语言
OranTech42 分钟前
第28节课-夕夕超市收银系统(下)-笔记
java
IDOlaoluo1 小时前
jakarta-tomcat-connectors-jk2-src.tar.gz 安装教程(详细步骤及附安装包)
java·tomcat
SheepHappy1 小时前
MyBatis-Plus 源码阅读(三)条件构造器原理深度剖析
java·源码阅读