- 论坛徽章:
- 0
|
// String share = "Hello"; // sharing way;
// String selfish = new String ("Hello" ); // selfish way;
public class tryString {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String a = "Hello";
String b = "Hello";
String c = new String ("Hello" );// this guy do not share "Hello" with
// friends born earlier or later than himself
String d = new String ("Hello!" );
String e = "Hello";
String f = "Hello!"; // the JV CAN rEcOgnIsE that d is born in that selfish
// a way that d will not share "Hello!" with f, so
// f have to create a new "Hello!" himself.
System.out.println(b==a);
System.out.println(c==a);
System.out.println(e==a);
System.out.println(e==c);
System.out.println(f==d);
}
}
OUTPUT:
true
false
true
false
false |
|