aspose file tools*
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 Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Integer Problem" Watch "Integer Problem" New topic
Author

Integer Problem

Prashant Kataria
Greenhorn

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

if(i==new Integer(10)){
System.out.print("i");
}
if(i==j){
System.out.print("j");
}

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.

http://www.coderanch.com/t/259111/java-programmer-SCJP/certification/Wrapper-equality
[ 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��
 
 
subject: Integer Problem