本人支付人民币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);//
    }
    
}
相关推荐
suaizai_1 分钟前
ComputerUse:让AI真正操控桌面系统
java·前端·javascript
傲世仙尊9 分钟前
C++起步-命名空间解决命名冲突与cin-cout缺省参数
开发语言·c++
fundoit12 分钟前
资源服务器如何对 JWT 进行验签
java·运维·服务器·spring boot·php·oauth2
hljqwb12 分钟前
java服务异常日志只打印异常类型,没有堆栈定位分析(十)
java·开发语言
ym hyd 11116 分钟前
生鲜超市库存管理信息系统源码 Java+SpringBoot+Vue3 前后分离
java·开发语言·vue.js·spring boot·毕设
haerapi18 分钟前
KingbaseES 全文检索实战之前:先建立中文搜索的可解释基线
开发语言·python·全文检索
徐小黑ACG19 分钟前
Golang 基础02 控制语句
开发语言·后端·golang
Rain的Java大神之路21 分钟前
别再瞎装 RabbitMQ 了!从 0 到 1 部署到 Spring Boot 全链路实战,生产级坑全填平
java·后端·面试
liyunlong-java24 分钟前
敏感词过滤完整指南(DFA 字典树)
java·开发语言·spring
专业程序开发源25 分钟前
SSM笔记本在线销售系统32649-计算机课程设计、毕业设计
java·spring boot·后端·python·django·php·课程设计