How to Convert Boolean Object to String Object

/*
 * Here we will learn to conver Boolean Object to String Object
 */
public class ConvertBooleanToString {
	public static void main(String[] args) {

		/*
		 * 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 as false.
		 */
		Boolean boolObj = new Boolean("");

		/*
		 * As boolObj is a string it will have method named toString from Object
		 * class that can be used to convert Boolean Object to String Object.
		 *
		 * Note*: Boolean Object Overrides the toString method from Object class
		 */

		/*
		 * toString() method returns a String object representing this Boolean's
		 * value. If this object represents the value true, a string equal to
		 * "true" is returned. Otherwise, a string equal to "false" is returned.
		 */
		String strBoolean = boolObj.toString();

		System.out.println("Value of String Object :" + strBoolean);

	}
}

 

By | 2017-07-24T12:32:06+00:00 October 1st, 2012|Code Base|0 Comments

About the Author:

Leave A Comment