JAVA对象的比较测试

来源:互联网 发布:网络电视怎么看3d电影 编辑:程序博客网 时间:2024/05/18 09:25
/**
 * 
 * @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