![java package tutorial](/java/lang/images/java.jpg)
- Java.lang Package classes
- Java.lang - Home
- Java.lang - Boolean
- Java.lang - Byte
- Java.lang - Character
- Java.lang - Character.Subset
- Java.lang - Character.UnicodeBlock
- Java.lang - Class
- Java.lang - ClassLoader
- Java.lang - Compiler
- Java.lang - Double
- Java.lang - Enum
- Java.lang - Float
- Java.lang - InheritableThreadLocal
- Java.lang - Integer
- Java.lang - Long
- Java.lang - Math
- Java.lang - Number
- Java.lang - Object
- Java.lang - Package
- Java.lang - Process
- Java.lang - ProcessBuilder
- Java.lang - Runtime
- Java.lang - RuntimePermission
- Java.lang - SecurityManager
- Java.lang - Short
- Java.lang - StackTraceElement
- Java.lang - StrictMath
- Java.lang - String
- Java.lang - StringBuffer
- Java.lang - StringBuilder
- Java.lang - System
- Java.lang - Thread
- Java.lang - ThreadGroup
- Java.lang - ThreadLocal
- Java.lang - Throwable
- Java.lang - Void
- Java.lang Package extras
- Java.lang - Interfaces
- Java.lang - Errors
- Java.lang - Exceptions
- Java.lang Package Useful Resources
- Java.lang - Useful Resources
- Java.lang - Discussion
Java - Boolean booleanValue() Method
Description
The Java Boolean booleanValue() returns the value of this Boolean object as a boolean primitive.
Declaration
Following is the declaration for java.lang.Boolean.booleanValue() method
public boolean booleanValue()
Parameters
NA
Return Value
This method returns the primitive boolean value of this object.
Exception
NA
Getting Primitive boolean from Boolean Object of true value Example
The following example shows the usage of Boolean booleanValue() method. In this program, we've created a Boolean variable and assigned it a Boolean Object of true value. Then using booleanValue(), the underlying value of Boolean variable is assigned to primitive boolean variable and result is printed.
package com.tutorialspoint; public class BooleanDemo { public static void main(String[] args) { // create a Boolean object b Boolean b; // assign value to b b = new Boolean(true); // create a boolean primitive type bool boolean bool; // assign primitive value of b to bool bool = b.booleanValue(); String str = "Primitive value of Boolean object " + b + " is " + bool; // print bool value System.out.println( str ); } }
Output
Let us compile and run the above program, this will produce the following result −
Primitive value of Boolean object true is true
Getting Primitive boolean from Boolean Object of false value Example
The following example shows the usage of Boolean booleanValue() method. In this program, we've created a Boolean variable and assigned it a Boolean Object of false value. Then using booleanValue(), the underlying value of Boolean variable is assigned to primitive boolean variable and result is printed.
package com.tutorialspoint; public class BooleanDemo { public static void main(String[] args) { // create a Boolean object b Boolean b; // assign value to b b = Boolean.valueOf(false); // create a boolean primitive type bool boolean bool; // assign primitive value of b to bool bool = b.booleanValue(); String str = "Primitive value of Boolean object " + b + " is " + bool; // print bool value System.out.println( str ); } }
Output
Let us compile and run the above program, this will produce the following result −
Primitive value of Boolean object false is false
Getting Primitive boolean from Boolean Object of false value Example
The following example shows the usage of Boolean booleanValue() method. In this program, we've created a Boolean variable and assigned it a Boolean Object of false value. Then using booleanValue(), the underlying value of Boolean variable is assigned to primitive boolean variable and result is printed.
package com.tutorialspoint; public class BooleanDemo { public static void main(String[] args) { // create a Boolean object b Boolean b; // assign value to b b = Boolean.valueOf(false); // create a boolean primitive type bool boolean bool; // assign a primitive value to Boolean object b = true; // assign primitive value of b to bool bool = b.booleanValue(); String str = "Primitive value of Boolean object " + b + " is " + bool; // print bool value System.out.println( str ); } }
Output
Let us compile and run the above program, this will produce the following result −
Primitive value of Boolean object true is true