• Post Reply Bookmark Topic Watch Topic
  • New Topic

boolean comparision  RSS feed

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Boolean b1 = new Boolean(“yes”);
Boolean b2 = new Boolean("no");
System.out.println(b1.equals(b2));

i'm geting result : true...

tha value in b1 is yes and b2 is no...

how it is possible to get true....

could you state the reason please...
 
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The answer is in the API of the Boolean class. Check it.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Ramakrishna", you've been warned several times about our naming policy. Don't ignore the warnings, and change your name as explained in the Naming Policy.
 
Ranch Hand
Posts: 71
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ram,

If you construct a Boolean object other then with the "true" string, it evaluate it as false


Both evaluates false, and due to overriding equals() method it checks meaningfully equals which returns true.

welcome,

 
Ramakrishna Konanki
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanq

Sudhakar Sharma wrote:Hi Ram,

If you construct a Boolean object other then with the "true" string, it evaluate it as false


Both evaluates false, and due to overriding equals() method it checks meaningfully equals which returns true.

welcome,

 
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Read this, Sudhakar Sharma, which appears on the Beginning Java title page.
We're all here to learn, so when responding to others, please focus on helping them discover their own solutions, instead of simply providing answers.
By giving a straight answer, you have deprived Ramakrishna Konanki of the chance to learn for himself. Christophe's suggestion was far better; he would have remembered the answer longer, and learned about the API documentation, if he had looked it up for himself. It would only have taken a few seconds to find the answer from the API.
 
Sudhakar Sharma
Ranch Hand
Posts: 71
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for reminding me the policy of the forum, next time I will care of this.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!