• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

boolean comparision

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 79180
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for reminding me the policy of the forum, next time I will care of this.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic