Java - Boolean class
Java - Boolean class
Learn Java in-depth with real-world projects through our Java certification course. Enroll and
become a certified expert to boost your career.
static Boolean FALSE − This is the Boolean object corresponding to the primitive value
false.
static Boolean TRUE − This is the Boolean object corresponding to the primitive value
true.
static Class<Boolean> TYPE − This is the Class object representing the primitive type
boolean.
Boolean(boolean value)
1
This allocates a Boolean object representing the value argument.
Boolean(String s)
2 This allocates a Boolean object representing the value true if the string argument is
not null and is equal, ignoring case, to the string "true".
100% Placement Assistance. Weekdays
Open
& Weekend Batches. Enroll now.
Page 2 of 4
boolean booleanValue()
1
This method returns the value of this Boolean object as a boolean primitive.
int compareTo(Boolean b)
2
This method compares this Boolean instance with another.
int hashCode()
5
This method returns a hash code for this Boolean object.
String toString()
11
This method returns a String object representing this Boolean's value.
Methods Inherited
This class inherits methods from the following classes −
java.lang.Object
Open Compiler
package com.tutorialspoint;
public class BooleanDemo {
public static void main(String[] args) {
// compare b1 with b2
res = b1.compareTo(b2);
System.out.println( str2 );
} else if( res < 0 ) {
System.out.println( str3 );
}
}
}
Output
Let us compile and run the above program, this will produce the following result −