public class Animal {
public static void main(String[] args) {
String s = "hell";
String sone = "hell";
String stwo = new String("hell");
String sthree = new String("hell");
System.out.println(s==sone);
System.out.println(s==stwo);
System.out.println(s==sthree);
System.out.println(stwo==sthree);
}
}

本文通过一个简单的 Java 示例代码展示了如何使用 String 类型,并重点分析了字符串实例间的比较方法及其实现原理。代码中创建了多个 String 对象并使用 == 运算符进行了比较,以此来说明 Java 中字符串池的概念及其工作方式。

被折叠的 条评论
为什么被折叠?



