wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Boolean wrapper class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Boolean wrapper class" Watch "Boolean wrapper class" New topic
Author

Boolean wrapper class

preeti khane
Ranch Hand

Joined: Mar 12, 2003
Posts: 93
Could someone explain , when the Boolean wrapper class equates to true / false when comparing 2 objects... I have seen that this class acts different compared to the other wrapper classes... and has some similarity with the String class (in terms of the true/false literals)
Anupam Sinha
Ranch Hand

Joined: Apr 13, 2003
Posts: 1088
Boolan objects if created by passing in a String will be true if the String passed is true(in any case). So True, TrUe, tRuE, TRUE and any other combination of cases in the same order will cause the Boolean object to contain true. Any other value will cause the wrapper to contain false. When toString is used then however the value that will be printed will be however true or false(in lowercase). Consider this :

Hope that helps.
Marlene Miller
Ranch Hand

Joined: Mar 05, 2003
Posts: 1391
Here is the code from Boolean.java (1.4.1)
pinky yadav
Ranch Hand

Joined: Jun 17, 2002
Posts: 44
one more point the static valueOf(boolean) and valueOf(String) method return reference to the static Boolean object in the class Boolean.
thus the following code gives the output as:
false
true
 
 
subject: Boolean wrapper class