1)输出false是(C)
- Integer i01=59;
- int i02=59;
- Integer i03=Integer.valueOf(59);
- Integer i04=new Integer(59);
*A System.out.println(i01==i02);
*B System.out.println(i01==i03);
*C System.out.println(i03==i04);
*D System.out.println(i02==i04);
解析
Byte,Short,Integer,Long,Character这5种整型的包装类也只是在对应值小于等于127并且大于等于-128时才可使用常量池,因为他们至占用一个字节(-128~127);
public class Test1 {
public static void main(String[] args) {
Integer a = 127;
Integer b = 127;
Integer c = 128;
Integer d = 128;
System.out.println(a == b);
System.out.println(c == d);
System.out.println(c == 128);
}
/*true
false
true*/
}