public static void main (String[] args) {
String s1 = new String("hello");
String s2 = new String("hello");
s1.intern();
s2.intern();
System.out.println(s1 == s2); // why this returns false ?
}
Run Code Online (Sandbox Code Playgroud)
根据我的理解,第一次调用实习方法应该创建一个带有单个字符串的"字符串实习池" "hello".第二次调用实习方法没有做任何事情(因为"hello"字符串已经存在于池中).现在,当我说s1 == s2我希望JVM比较"hello"字符串实习池中的字符串并返回时true.
我正在阅读有关 B 树的内容,很有趣的是,它是专门为存储在辅助内存中而构建的。但我对以下几点感到有点困惑: