Convert primitive boolean value to an object
We can use the Boolean wrapper class for converting a primitive boolean value to an object.
public class BooleanWrapper {
public static void main(String args[]) {
boolean bool = true;
Boolean objBool = Boolean.valueOf(bool);
System.out.println(objBool);
}
}
or
public class BooleanWrapper {
public static void main(String[] args) {
boolean bool = true;
Boolean objBool = new Boolean(bool);
System.out.println(objBool);
}
}
The first method would perform better. So it is the recommended way of creating a wrapper class for primitive boolean type.
Tags: Boolean, Boolean examples, boolean to Object, java.lang, java.lang.Boolean
You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
Leave a Reply