File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
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!