//==比较的是变量的地址值,而String类重写了object类的equals方法,比较的是字符序列
String a="hello";
String b="word";
String c="helloword";
String d=new String("helloword");
System.out.println(c==a+b);//false,两个变量,先找,后拼接
System.out.println(c=="hello"+"word");//true,两个常量先拼接,再在常量池中找
System.out.println(c==d);//false
System.out.println(c.equals(d));
System.out.println(c.equals(a+b));//true
System.out.println(+'a');//97
System.out.println(+'0');//48
System.out.println(+'A');//65
java-StringAPI中的==与equals的辨析
最新推荐文章于 2024-10-01 09:29:45 发布