HOME      BLOG       FORUMS      CONTACT       ABOUT

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.

Share

Tags: , , , ,


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.

AddThis Social Bookmark Button

Leave a Reply