String s1 = "china"; String s2 = "china"; String s3 = "china"; String ss1 = new String("china"); String ss2 = new String("china"); String ss3 = new String("china");
int i1 = 9; int i2 = 9; int i3 = 9; public static final int INT1 = 9; public static final int INT2 = 9; public static final int INT3 = 9;
String s0 = "abc"; String s1 = "abc"; System.out.println(s0==s1); //true 可以看出s0和s1是指向同一个对象的。
String s0 =new String ("abc"); String s1 =new String ("abc"); System.out.println(s0==s1); //false 可以看出用new的方式是生成不同的对象 System.out.println(s0.equals(s1)); //true 可以看出equals比较的是两个String对象的内容(值)
String s0="helloworld"; String s1="helloworld"; String s2="hello" "word"; System.out.println( s0= =s1 ); //true 可以看出s0跟s1是同一个对象 System.out.println( s0= =s2 ); //true 可以看出s0跟s2是同一个对象
String s0="helloworld"; String s1=new String("helloworld"); String s2="hello" new String("world"); System.out.println( s0==s1 ); //false System.out.println( s0==s2 ); //false System.out.println( s1==s2 ); //false
String s0 = "a1"; String s1 = "a" 1; System.out.println((s0 == s1)); //result = true String s2 = "atrue"; String s3= "a" "true"; System.out.println((s2 == s3)); //result = true String s4 = "a3.4"; String s5 = "a" 3.4; System.out.println((a == b)); //result = true
String s0 = "ab"; String s1 = "b"; String s2 = "a" s1; System.out.println((s0 == s2)); //result = false
String s0 = "ab"; final String s1 = "b"; String s2 = "a" s1; System.out.println((s0 == s2)); //result = true
String s0 = "ab"; final String s1 = getS1(); String s2 = "a" s1; System.out.println((s0 == s2)); //result = false private static String getS1() { return "b"; }