String compare

有些对象重写了Object.equals() 方法 String,Date,Byte,Integer,Short,Character,Long,Float,Double,Boolean 

public
class Student { public static void main(String[] args) { String s1 = new String("123"); String s2 = new String("123"); String s3 = "123"; String s4 = "123"; System.out.println(s1 == s2); //false System.out.println(s1.equals(s2)); //true System.out.println(s3 == s4); //true System.out.println(s3.equals(s4)); //true } }

 

posted @ 2015-02-18 16:02  牧 天  阅读(108)  评论(0)    收藏  举报