java - how to use primitive types properly -
int x = 10; int y = 10; integer x1 = new integer(10); integer y1 = new integer(10); system.out.println(x == y); system.out.println(x1 == y1);
the first sop print true whereas second 1 print false. actual problem ?
the second approach not checking values rather objects.
if want compare values of 2 integer objects have use appropriate methods compareto(integer)
like mentioned in comments if want check equality can use equals
Comments
Post a Comment