+ 5
What's the difference between int and Integer? Plz explain...
Integer a=10; Integer b=10; if (a==b) ; // this results false ! // if a and b are declared as int if stmt is true!
9 Respostas
+ 13
In this case, you are not comparing integers. You are comparing objects. Two object won't be equal even if they have same data.
+ 7
a==b doesn't check integer values and doesn't check object equality, it checks object references. The two Integer objects are different objects so theirs references are different even if they are equals (equals method would return true)
+ 5
for each primitive type there exists a wrapper type (Character, Integer, Double). These are objects as String or any other non-primitive type.
with == you compare the reference of objects. the same reason why string comparison only works with equals instead of ==.
+ 4
Then I'll nod If I'm rock đ
+ 2
int is just a keyword(or data type) but Integer is a class
Integer a = 10;
Integer b = 10;
if(a==b) System.out.print("true");
And that "if statement" always be true,bro
+ 2
In your case "a" and "b" are the two objects of class "Integer". Two objects can't be same as their reference is different.
But "int" is data type not a class
0
thx for all of ur answers. .. u all rock ! I got the answer
0
đ