String.equals()比较内容,而==检查引用是否指向同一对象。
请参阅下面的插图示例-
public class Tester {
public static void main(String[] args) {
String test = new String("a");
String test1 = new String("a");
System.out.println(test == test1);
System.out.println(test.equals(test1));
}
}输出结果
false true