深入理解JAVA常量池

*1.

Integer i1 = 127;
Integer i2 = 127;
System.out.println(i1 == i2);
*2.

Integer i3 = 128;
Integer i4 = 128;
System.out.println(i3 == i4);
*3.

Character c1 = 'a';
Character c2 = 'a';
System.out.println(c1 == c2);
*4.

Boolean e1 = false;
Boolean e2 = false;
System.out.println(e1 == e2);
*5.

Double g1 = 1.0;
Double g2 = 1.0;
System.out.println(g1 == g2);
*6.

Integer i4 = new Integer(40);
Integer i5 = new Integer(40);
Integer i6 = new Integer(0);
System.out.println(i4 == i5 + i6);
*7.

Integer i5 = new Integer(40);
Integer i6 = new Integer(0);
System.out.println(40 == i5 + i6);
*8.

String s1 = "hello";
String s2 = "he" + "llo";
System.out.println(s1 == s2);
*9.

String a = "ab";
final String bb = "b";
String b = "a" + bb;
System.out.println(a == b);
*10.

String s = "he" + "llo"; 
String a = "he";
String b = "llo";
String s1 = a + b;
System.out.println(s == s1);
*11.

String s1 = new String("he") + new String("llo");
s1.intern();
String s2 = "hello";
System.out.println(s1 == s2);
*12.

String s1 = new String("he") + new String("llo");
String s3 = new String("hello");
s1.intern();
String s2 = "hello";
System.out.println(s1 == s2);
*13.

String s1 = new String("he") + new String("llo");
s1.intern();
String s3 = new String("hello");
String s2 = "hello";
System.out.println(s1 == s2);
*14.

String str1 = new StringBuilder("he").append("llo").toString();
System.out.println(str1 == str1.intern());
*15.

String str2 = new StringBuilder("ja").append("va").toString();
System.out.println(str2 == str2.intern());
加载中...
如果由于网络原因导致此框一直不消失,请重新刷新页面!