== does it work with Integer

We all know if we have to compare two different strings we should use equals method instead of ‘==’ operator but what about Integer.

If you are comparing Integer(Wrapper not int) you should not use ‘==’ operator because it works 0 to upto 127

Integer i=127;

Integer j=127;

System.out.println(i==j);

it’s output will be true but instead of 127 if you use 128 this will give you false 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s