class string{
static String str = new String("yes");
string(){}
}
public class rtyh {
public static void main(String[] args){
string strr = new string();
String st = new String("yes");
String str = new String("yes");
String str1 = "yes";
String str2 = "yes";
System.out.println(str1==str2);
System.out.println(st.equals(str));
System.out.println(st==str);
System.out.println(str.equals(strr.str));
System.out.println(str==strr.str);
}
}
结果为 ture
ture
ture
ture
false
所以,==用来对引用的判断,如果是引用的同一个内存单元则相等,否则不相等.equals()用来对字符串内容的逐一判断.