• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

query in answer

 
Rajni Patel
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



public class Test4 {
public static void main(String[] args) {
Test4 t = new Test4();
int i1 = 2000;
int i2 = 2000;
int i3 = 2;
int i4 = 2;
Integer Ithree = new Integer(2);
Integer Ifour = new Integer(2);
System.out.println(Ithree == Ifour);
t.methodA(i3,i4);
t.methodA(i1,i2);
}
public void methodA(Integer i, Integer eye){
System.out.println(i == eye);
}
}


so Answer would be :
false
true
false

I understand first two false and true but in last one is false how?

 
Ankur kothari
Ranch Hand
Posts: 531
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i1==i2 or i==eye will return true only if their values are between -128 to 127 inclusive......else they will give false

this link will help you a bit too

http://www.coderanch.com/t/472339/Programmer-Certification-SCJP/certification/equals
 
Rajni Patel
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for reply.

Could you tell me, in which link this topic has mentioned?
 
Ankur kothari
Ranch Hand
Posts: 531
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
wrappers.....k&B book
 
Muhammad Khojaye
Ranch Hand
Posts: 449
IntelliJ IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also see here
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic