public class Test {
public static void main(String[] args) {
String a = "abc";
String b = "abc";
String c = new String("abc");
String d = "ab" + "c";
System.out.println("a == b" + a == b); //false
System.out.println("a == c" + a == c); //false
System.out.println("a == d" + a == d); //false
System.out.println("b == c" + b == c); //false
System.out.println("b == d" + b == d); //false
System.out.println("c == d" + c == d); //false
}
}
刚看到这段代码的时候,我就???(这作者是个傻子吧?)
后来。。。我复制粘贴去idea上运行了得到以下结果:我震惊了(哈哈哈)
后来想了下,给表达式加上左右括号()。--(Boolean)可有可无,方便理解。
最近看到几道String的题目,大家可以做一下,有需要的话我会在评论区提供答案。