Boolean wrapper class is used to wrap primitive data type boolean value in an object.
Examples of Boolean Wrapper Class
Example 1 : Convert Boolean Object to boolean data type
public class BooleanToboolean
{
public static void main(String[] args)
{
Boolean bObj = new Boolean("true");
boolean b = bObj.booleanValue();
System.out.println(b);
}
}
Output
true
This example show how a Boolean object can be converted to a boolean data type.
Example 2 : Convert String Object to Boolean Object
public class StringToBoolean
{
public static void main(String[] args)
{
String str = "true";
Boolean bObj1 = new Boolean(str);
System.out.println(bObj1);
Boolean bObj2 = Boolean.valueOf("false");
System.out.println(bObj2);
}
}
Output
true
false
This example shows how to convert String object to a Boolean object.