本人支付人民币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);//
    }
    
}
相关推荐
TIEM_69几秒前
C++string|遍历、模拟实现、赋值拷贝现代写法
开发语言·c++
贫民窟的勇敢爷们4 分钟前
SpringBoot多环境配置全解+配置优先级管控
java·spring boot·后端
计算机安禾6 分钟前
【c++面向对象编程】第14篇:多态(一):虚函数——实现“一个接口,多种方法”
开发语言·c++
tellmewhoisi10 分钟前
单独抽取用户服务(请求不通):feign添加拦截器(添加token)
java·开发语言
YL2004042622 分钟前
035LRU缓存
java·leetcode·缓存
basketball61623 分钟前
C++ Lambda 表达式完全指南
开发语言·c++·算法
不知名的老吴24 分钟前
C++中emplace函数的不适场景总结(三)
开发语言·c++·算法
Java面试题总结34 分钟前
Go 里什么时候可以“panic”?
开发语言·后端·golang
rit843249935 分钟前
基于MATLAB平台的指纹识别系统实现
开发语言·matlab
不像程序员的程序媛38 分钟前
mysql 0000-00-00 00:00:00零日期问题
java·mysql