-1

as far as I understand due to Java autoboxing I can do this:

Integer i = 10;
Integer j = 10;
boolean b = i == j;

Or this:

int ii = 10;
int jj = 10;
Integer i = ii;
Integer j = jj;
boolean b = i == j;

In both cases b is TRUE. Then if Integer.parseInt() function returns an int in theory I can do this:

Integer i = Integer.parseInt("10");
Integer j = Integer.parseInt("10");
boolean b = i == j;

In this case b is also TRUE. Then if I do this b should be true as well:

Integer i = Integer.parseInt("200");
Integer j = Integer.parseInt("200");
boolean b = i == j;

Actually here b is FALSE. Anyone has an idea of what is going on? Thanks.

mmong
  • 64
  • 2

1 Answers1

1

You should never use == between Integers.. It sometimes works only because certain values (I think below 128) are cached by Integer.valueOf() for performance reasons.

xs0
  • 2,990
  • 17
  • 25