public class Test_String {public static void main(String[] args) {String a = new String("aa");String b = new String("aa");System.out.PRintln(a == new String("aa")); //false == 判断 指向的是不是同一个对象 new 时会创建对象System.out.println("a == b " + (a == b)); //falseSystem.out.println("a.equals(b) " + (a.equals(b))); //true a.equals(b)判断两个对象的内容是否相等 System.out.println(a.equals(new String("aa"))); //true}
}
新闻热点
疑难解答