| Author |
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"); System.out.println(bl2); }}
|
SCJP 5 , SCWCD 5
|
 |
arulk pillai
Author
Ranch Hand
Joined: May 31, 2007
Posts: 3190
|
|
check the package name in the import statements. Sorry, it exists in Java 5 (i.e. is 1.5.0 onwards). http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Boolean.html [ October 26, 2008: Message edited by: arulk pillai ]
|
Java Interview Questions and Answers Blog | Amazon.com profile | Java Interview Books
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
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 ).
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
 |
|
|
subject: Boolean class (Wrapper)
|
|
|