parent
54179304da
commit
159854552f
@ -0,0 +1,15 @@
|
||||
package flyWeight;
|
||||
|
||||
public class StringTest {
|
||||
public static void main(String[] args) {
|
||||
String s1 = "abc";
|
||||
String s2 = "abc";
|
||||
String s3 = new String("abc");
|
||||
String s4 = new String("abc");
|
||||
System.out.println(s1 == s2); // true
|
||||
System.out.println(s1 == s3); // false
|
||||
System.out.println(s3 == s4); // false
|
||||
System.out.println(s3.intern() == s4.intern()); // true intern()从常量池找
|
||||
System.out.println(s3.intern() == s1); // true
|
||||
}
|
||||
}
|
Loading…
Reference in new issue