Home »
Java programming language
Java - Boolean Class parseBoolean() Method
Boolean class getBoolean() method: Here, we are going to learn about the getBoolean() method of Boolean class with its syntax and example.
By Preeti Jain Last updated : March 17, 2024
Boolean class getBoolean() method
- getBoolean() method is available in java.lang package.
- getBoolean() method is used to return the system property in boolean values either true or false.
- getBoolean() method is a static method, it is accessible with the class name too and if we try to access the method with the class object then also we will not get an error.
- getBoolean() method does not throw an exception at the time of returning system property.
Syntax
public static boolean getBoolean(String sys_prop);
Parameters
- String sys_prop – represents the string value (system _property) to be parsed.
Return Value
The return type of this method is boolean - it returns the corresponding boolean value that represent the String value.
Note: If the given argument system_property exists and the value is equal to true, it returns true.
Example
// Java program to demonstrate the example
// of getBoolean(String sys_prop) method of Boolean class
public class GetBooleanOfBooleanClass {
public static void main(String[] args) {
String sys_prop1 = "Is Java8 exists";
String sys_prop2 = "Is C++ not support OOPS";
// By setting property value by using
// setProperty(propertyname , value) method
System.setProperty(sys_prop1, "true");
System.setProperty(sys_prop2, "false");
// Store result in boolean variables
boolean b1 = Boolean.getBoolean(sys_prop1);
boolean b2 = Boolean.getBoolean(sys_prop2);
// Display result
System.out.println("Boolean.getBoolean(sys_prop1): " + b1);
System.out.println("Boolean.getBoolean(sys_prop2): " + b2);
}
}
Output
Boolean.getBoolean(sys_prop1): true
Boolean.getBoolean(sys_prop2): false