This week's book giveaway is in the JDBC forum.
We're giving away four copies of Make it so: Java DB Connections & Transactions and have Marcho Behler on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Integer Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Make it so: Java DB Connections & Transactions this week in the JDBC forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Integer Problem" Watch "Integer Problem" New topic

Integer Problem

Prashant Kataria

Joined: Sep 16, 2006
Posts: 3
Integer i=10;
Integer j=10;

if(i==new Integer(10)){

output should be "ij" but it only prints j why? if someone help me
Aniket Patil
Ranch Hand

Joined: May 02, 2006
Posts: 218
new Integer(10) newly creates an object on a heap. This is why 'i' is not printed out.
[ September 17, 2006: Message edited by: Aniket Patil ]

SCJP 5.0 | SCWCD 1.4 <br /> <br />If you don't know where you are going, any road will take you there!
Kidd He
Ranch Hand

Joined: Sep 17, 2006
Posts: 65
i==new Integer(10) creat a new Integer object,and "==" is used for checking the reference not the meaningful object's value.
Try equals(),and then it will do that!

SCJP1.4 93%<br />SCWCD��
I agree. Here's the link:
subject: Integer Problem
It's not a secret anymore!