Sunday, December 21, 2014

Integer wrapper return true from range -128 to 127

We are already familiar with boxing and auto boxing of wrapper to premitives and vice-verse.

See the below example.

    Integer integer1=127;
    Integer integer2=127;

    System.out.println(integer1==integer2);//The output will be true.
   
But as we increase the value from 127 to 128 you will see the output is different.
   
    Integer integer1=128;
    Integer integer2=128;

    System.out.println(integer1==integer2);//The output will be False.

As per JLC the boxed value returns true for int or short in the range of -128 to 127(included). It also returns true for a byte or a char in the range of \u0000 to \u007f.



No comments:

Post a Comment

Spring Boot Config Server and Config Client.

 In Spring cloud config we can externalise our configuration files to some repository like GIT HUT, Amazon S3 etc. Benefit of externalising ...