标签:
public class StringDemo { public static void main(String[] args) { // TODO Auto-generated method stub String str = "abc"; String str2 = "abc"; //System.out.println(str==str2); //true //System.out.println(str.equals(str2)); //true String str3 = new String("abc"); String str4 = "abc"; //System.out.println(str3==str4); //false //System.out.println(str3.equals(str4)); // true String str5 = "ab"+"c"; String str6 = "a"+"bc"; //System.out.println(str5==str6); // true //System.out.println(str5.equals(str6)); //true String str7 = "ab"; String str8 = str7+"c"; String str9 = "ab"+"c"; //System.out.println(str8.equals(str9)); // true //System.out.println(str8 == str9); // false --str8 是运行时的变量,而str9是字符串常量表达式 String str10 = "abc"; String str11 = new String("abc"); String str12 = str11.intern(); System.out.println(str10 == str11); //false System.out.println(str10.equals(str11)); //true System.out.println(str11.equals(str12)); //true } }
标签:
原文地址:http://www.cnblogs.com/childhooding/p/4642614.html