Scroll to top

How to Convert String Object to Boolean Object

 * Here we will learn to convert String Object to Boolean Object.
public class ConvertStringToBoolean {

	public static void main(String[] args) {

		String strBoolFalse = "garbage value";

		String strBoolFalse1 = "";

		// String will be compared with "true" value ignoring case.
		String strBoolTrue = "trUE";

		 * Boolean constructor with String argument allocates a Boolean object
		 * representing the value true if the string argument is not null and is
		 * equal(Ignoring case) to the string "true".
		 * Otherwise, for any other thing it allocates a Boolean object
		 * representing the value false.
		Boolean boolObjectTrue = new Boolean(strBoolTrue);
		Boolean boolObjectFalse = new Boolean(strBoolFalse);
		Boolean boolObjectFalse1 = new Boolean(strBoolFalse1);

		// Both two Object above will have value as False



Author avatar

Post a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.