Java.lang.Boolean Class

Java Boolean Class

The Boolean class in the Java.lang package encapsulates a value of the primitive type boolean in an object. A single field of type boolean is included in a Boolean object.

This class also has a number of methods for converting a boolean to a String and a String to a boolean, as well as additional boolean-related constants and methods.

Class declaration

The java.lang.Boolean class is declared as follows:

public final class Boolean
  extends Object
    implements Serializable, Comparable<Boolean>

Fields

Sl No. Fields & Description
1. static Boolean FALSE
The Boolean object corresponds to the primitive value false.
2. static Boolean TRUE
The Boolean object corresponds to the primitive value true.
3. static Class<Boolean> TYPE
The Class object represents the primitive type boolean.

java.lang.Boolean Methods

The following are the methods available in the Boolean class:.

 

S.N Methods & Description
1. boolean booleanValue()
Returns the value of this Boolean object as a boolean primitive.
2. static int compare(boolean x, boolean y)
Compares two boolean values.
3. int compareTo(Boolean b)
Compares this Boolean instance with another.
4. boolean equals(Object obj)
Returns true if and only if the argument is not null and is a Boolean object that represents the same boolean value as this object.
5. static boolean getBoolean(String name)
Returns true if and only if the system property named by the argument exists and is equal to the string “true”.
6. int hashCode()
Returns a hash code for this Boolean object.
7. static int hashCode(boolean value)
Returns a hash code for a boolean value; compatible with Boolean.hashCode().
8. static boolean logicalAnd(boolean a, boolean b)
Returns the result of applying the logical AND operator to the specified boolean operands.
9. static boolean logicalOr(boolean a, boolean b)
Returns the result of applying the logical OR operator to the specified boolean operands.
10. static boolean logicalXor(boolean a, boolean b)
Returns the result of applying the logical XOR operator to the specified boolean operands.
11. static boolean parseBoolean(String s)
Parses the string argument as a boolean.
12. String toString()
Returns a String object representing this Boolean’s value.
13. static String toString(boolean b)
Returns a String object representing the specified boolean.
14. static Boolean valueOf(boolean b)
Returns a Boolean instance representing the specified boolean value.
15. static Boolean valueOf(String s)
Returns a Boolean with a value represented by the specified string.

Methods inherited

This class inherits the methods of the following class:

  • java.lang.Object

 

To open the online compiler click here.

Also Read: Java – Type Casting

Leave a Reply

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