Java2all.com  

Boolean





Share This Topic -

Boolean class :

The Boolean class encapsulates a Boolean value. It defines FALSE and TRUE constants.

This class provides following constructors:

Boolean(Boolean b)

Boolean(String str)

Here, b is a Boolean value and str is the string equivalent of a Boolean value.

The methods associated with Boolean Class are as follows:

1. Boolean booleanValue()

2. Boolean equals(Boolean b)

3. String toString(Boolean b)

EX :

 import java.util.*;

public class Boolean_Demo
{
	public static void main(String args[])
	{
		Boolean b1 = new Boolean(true);
		Boolean b2 = new Boolean(false);
		System.out.println("Object B1 = " + b1);
		System.out.println("Object B2 = " + b2);
		Boolean b3 = new Boolean("true");
		Boolean b4 = new Boolean("false");
		System.out.println("Object B3 = " + b3);
		System.out.println("Object B4 = " + b4);
		System.out.println("Boolean Value = " + b1.booleanValue());	
		System.out.println("(b1==b2)? " + b1.equals(b2));	
		String S1 = b1.toString();
		System.out.println("String S1 " + S1);	
		
	}
}

 
Output :
 
Object B1 = true
Object B2 = false
Object B3 = true
Object B4 = false
Boolean Value = true
(b1==b2)? false
String S1 true