Convert a String to boolean object.
We can use the Boolean wrapper class for converting a String object to boolean object.
public class BooleanWrapper {
public static void main(String[] args) {
String str = "true";
Boolean objBool = new Boolean(str);
System.out.println(objBool);
}
}
or
public class BooleanWrapper {
public static void main(String[] args) {
String str = "true";
Boolean objBool = Boolean.valueOf(str);
System.out.println(objBool);
}
}
We can convert any String type to a Boolean object using the above code. Any value other than ‘true’ for the String would yield a Boolean object with value false.
Tags: Boolean, Boolean examples, Boolean wrapper class, 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