In this example we will show how to create a Boolean wrapper object in Java.
Source Code
package com.beginner.examples;
public class CreateBooleanWrapper {
public static void main(String[] args) {
//Create Boolean using boolean primitive type
boolean b1 = true;
Boolean booleanObject1 = new Boolean(b1);
System.out.println("Wrapper class Boolean output: " + booleanObject1);
//Create Boolean using string value
Boolean booleanObject2 = new Boolean("true");
System.out.println("Wrapper class Boolean output: " + booleanObject2);
//Create Boolean using value
Boolean booleanObject3 = new Boolean(true);
System.out.println("Wrapper class Boolean output: " + booleanObject3);
}
}
Output:
Wrapper class Boolean output: true
Wrapper class Boolean output: true
Wrapper class Boolean output: true