JAVA对象的比较测试

/**
 * 
 * @author caryt
 *
 */
public class test {
   
/**
* @param args
*/
static int x[]=new int[15];
public static void main(String[] args) {
// TODO Auto-generated method stub
String t1=new String("caryt");
String t2=new String("caryt");
System.out.println(t1==t2);//比较的是对象的引用
System.out.println(t1!=t2);//比较的是对象的引用

System.out.println(t1.equals(t2));//比较的是对象的

}

}

out: false
true
true

posted on 2013-06-27 10:09  caryt  阅读(98)  评论(0)    收藏  举报

导航