首页 > 编程知识 正文

java在哪里编写程序,java int和integer

时间:2023-05-04 12:17:09 阅读:146717 作者:3114

使用Integer和int==比较总结

system.out.println (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ );

integera=newinteger(3;

Integer b=3;

int c=3;

system.out.println(a==b ); //false

system.out.println(a==c );//真

Integer f1=100,f2=100,f3=150,f4=150;

system.out.println(F1==F2 );//真

system.out.println(F3==F4 ); //false

system.out.println (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ );

Integer i6=128;

Integer i7=128;

int i8=128;

system.out.println(I6==I7; //false

system.out.println(I6==I8 );//真

integerI=integer.valueof(128; //原理

system.out.println (_ _ _ _ _ _ _ _ _ _ _ _ _ ' );

Integer i9=12;

Integer i11=12;

system.out.println(I9==I11;//真

//输出结果

_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

假的

真的

真的

假的

_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

假的

真的

________________

真的

分析结果

要自动打开Integer的包装,请使用Integer.valueOf (

如果当前数值在-128和127之间,则根据上图的原理,一定为真。

因为在范围内,所以将此int值存储在缓存数组中,然后每次都去数组中查找此值。 如果找到则为true,如果找不到则为false。

如果当前数值超出范围,则此方法返回newinteger(I )并返回该值。

i6、i7为两种参照类型,超出范围时直接为newinteger(I )。 于是,两个参照类型的值比较地址值的结果为false。

i6、i8为integer,int --- i6开箱后变为int。 比较两种int类型的数值时为true。

剩下的结果相似

缓存数组的源代码

私有身份证明

静态金融低=-128;

静态金融入高;

静态final integer cache [ ];

静态{

//highvaluemaybeconfiguredbyproperty

int h=127;

stringintegercachehighpropvalue=

sun.misc.VM.getsavedproperty (Java.lang.integer.integer cache.high );

Integercachehighpropvalue!=空) {

try {

inti=parseint (integercachehighpropvalue;

I=math.max(I,127 );

//maximumarraysizeisinteger.max _ value

h=math.min(I,integer.max_value-(-low )-1 );

} catch (numberformatexceptionnfe ) {

//ifthepropertycannotbeparsedintoanint,ignore it。

}

}

high=h;

cache=new integer [ (高-低)1];

int j=low;

for(intk=0; k cache.length; k )

che[k]=newinteger(j;

//range [-128,127 ] must be interned (jls 75.1.7 ) )

assert IntegerCache.high=127;

}

私有集成电路

}

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。