一到千、在-128~127范圍內(nèi)的Integer對(duì)象
1昆码、以 Integer x = value 的方式賦值憨琳,只是進(jìn)行int原生數(shù)據(jù)類型的數(shù)值比較
Integer in1 = 20;
Integer in2 = 20;
System.out.println(in1 == in2); // true
2物咳、使用new操作創(chuàng)建新對(duì)象
Integer in3 = new Integer(20);
System.out.println(in1 == in3); // false
3锣险、Integer.valueOf解析成Integer對(duì)象后比較,不屬于創(chuàng)建新對(duì)象操作
System.out.println(in1 == Integer.valueOf(20)); // true
4所森、Integer.parseInt直接轉(zhuǎn)成了int類型
System.out.println(in1 == Integer.parseInt("20")); // true
二囱持、超出-128~127范圍的Integer對(duì)象
1、超出-128~127的范圍焕济,進(jìn)行==比較時(shí)是進(jìn)行地址及數(shù)值比較
Integer in4 = 200;
Integer in5 = 200;
System.out.println(in4 == in5); // false
2纷妆、Integer.valueOf解析成Integer對(duì)象后比較
System.out.println(in4 == Integer.valueOf(200)); // false
3、Integer.parseInt直接轉(zhuǎn)成了int類型
System.out.println(in4 == Integer.parseInt("200")); // true
4晴弃、Integer 與 int 比較的時(shí)候掩幢,是將Integer轉(zhuǎn)成int再比較兩個(gè)值大小
System.out.println(in4 == 200); // true