---
title: "JAVA对象的比较测试"
author: "caryt"
date: "2013-06-27T10:09:00Z"
tags: []
slug: "java"
draft: false
lastmod: "2014-04-25T10:57:18Z"
id: 2054456
url: "https://caryt.iteye.com/blog/2054456"
---

/\**  
\*  
\* @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