- public class IntegerClass {
- public static void main(String[] args) {
- Integer i1 = 11;
- Integer i2 = 11;
- if(i1 == i2){
- System.out.println("i1 == i2");
- }
- if(i1.equals(i2)){
- System.out.println("i1.equals(i2)");
- }
- /* * * * * * * * * * * * * * * * * * * * * */
- Integer i3 = 128;
- Integer i4 = 128;
- if(i3 == i4){
- System.out.println("i3 == i4");
- }else{
- System.out.println("i3 != i4");
- }
- /* * * * * * * * * * * * * * * * * * * * * */
- if(i3.equals(i4)){
- System.out.println("i3.equals(i4)");
- }else{
- System.out.println("!(i3.equals(i4))");
- }
- }
- }
Thanks to compiler which actually autoboxes primitive values to corresponding wrapper classes.