Problem trying to compare 2 values of type Integer in IF condition

I havd pop a value of type Integer from a stack into a variable, but the If conditions does not seem to work:

iqueuedVar = conn3.removeFromFeed();

System.out.println(iqueuedVar);

Integer test = new Integer(123);

if(test == iqueuedVar)

{

System.out.println("It Works !!");

....

....

The Integer test searched for the popped value 123 - which exists - but the IF condition is not working.

I'm using API 1.4.2 - Please help ?

[490 byte] By [Godela] at [2007-10-1 21:49:43]
# 1
You're comparing object references. Use equals() to test the equality of the objects, or get an int value with the intValue() method to compare with the == operator.
yawmarka at 2007-7-13 7:52:44 > top of Java-index,Java Essentials,New To Java...
# 2
test is reference, not an int.
Arbiea at 2007-7-13 7:52:44 > top of Java-index,Java Essentials,New To Java...
# 3

> I havd pop a value of type Integer from a stack into

> a variable, but the If conditions does not seem to

> work:

>

> iqueuedVar = conn3.removeFromFeed();

> System.out.println(iqueuedVar);

> Integer test = new Integer(123);

> if(test == iqueuedVar)

> {

>System.out.println("It Works !!");

> ....

> ....

>

> The Integer test searched for the popped value 123 -

> which exists - but the IF condition is not working.

>

> I'm using API 1.4.2 - Please help ?

get the int value from Integer.Then compare two int value

tiptipa at 2007-7-13 7:52:44 > top of Java-index,Java Essentials,New To Java...
# 4
Thanks guy - doh !!
Godela at 2007-7-13 7:52:44 > top of Java-index,Java Essentials,New To Java...