1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
/* Convert Boolean Object to boolean primitive exmaple This example show how a Boolean object can be converted to a boolean primitive type. */ public class JavaBooleanTobooleanExample { public static void main(String[] args) { //Construct a Boolean object. Boolean blnObj = new Boolean("true"); //use booleanValue of Boolean class to convert it into boolean primitive boolean b = blnObj.booleanValue(); System.out.println(b); } } /* Output would be : true */ |
next example should be about nullpointers… You use object boolean mostly in places where it can be null
This code is pretty much wrong. It completely ignores that Boolean values can be (and often are) null. NPE exceptions galore using this code.