This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Beginning Java and the fly likes Boolean class (Wrapper) 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 » Java » Beginning Java
Bookmark "Boolean class (Wrapper)" Watch "Boolean class (Wrapper)" New topic

Boolean class (Wrapper)

priya rishi
Ranch Hand

Joined: Oct 26, 2008
Posts: 119
This code is working,
but we dont have parseBoolean() in Boolean wrapper class.
Then how?

code is as follows:
class booleanDemo{
public static void main(String args[])
boolean bl2 = Boolean.parseBoolean("true");

arulk pillai
Ranch Hand

Joined: May 31, 2007
Posts: 3219
check the package name in the import statements. Sorry, it exists in Java 5 (i.e. is 1.5.0 onwards).
[ October 26, 2008: Message edited by: arulk pillai ]

Java Interview Questions and Answers Blog | profile | Java Interview Books
Rob Spoor

Joined: Oct 27, 2005
Posts: 19674

For Java 1.4 and earlier you can simply use Boolean.valueOf("true").booleanValue().

The trick is that Boolean.valueOf returns Boolean.TRUE or Boolean.FALSE. Not just object equal to those, but those very same objects themselves (well, references to them of course). So valueOf will not create a new Boolean object each time you use it, and therefore will be just one method call less efficient. In milliseconds, the difference will be 0, and you won't even notice it (unless perhaps you have billions of these calls ).

How To Ask Questions How To Answer Questions
I agree. Here's the link:
subject: Boolean class (Wrapper)