
- 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 Useful Resources
- Java.lang - Useful Resources
- Java.lang - Discussion
Java - Boolean parseBoolean(String s) Method
Description
The Java Boolean parseBoolean(String) parses the string argument as a boolean. The boolean returned represents the value true if the string argument is not null and is equal, ignoring case, to the string "true".
Declaration
Following is the declaration for java.lang.Boolean.parseBoolean() method
public static boolean parseBoolean(String s)
Parameters
s − the String containing the boolean representation to be parsed
Return Value
This method returns the boolean represented by the string argument.
Exception
NA
Parsing a String Value as true Boolean Example
The following example shows the usage of Boolean parseBoolean() method for a string value as true. In this program, we've a String "TRue" and using parseBoolean() method, we're parsing the "TRue" to a primitive boolean value of true and then result is printed.
package com.tutorialspoint; public class BooleanDemo { public static void main(String[] args) { // create and assign values to String s1 String s1 = "TRue"; // create 1 boolean primitive bool1 boolean bool1; /** * static method is called using class name * apply result of parseBoolean on s1 to bool1 */ bool1 = Boolean.parseBoolean(s1); String str1 = "Parse boolean on " + s1 + " gives " + bool1; // print b1 value System.out.println( str1 ); } }
Output
Let us compile and run the above program, this will produce the following result −
Parse boolean on TRue gives true
Parsing a String Value as false Boolean Example
The following example shows the usage of Boolean parseBoolean() method for a string value as "Yes". In this program, we've a String "Yes" and using parseBoolean() method, we're parsing the "Yes" to a primitive boolean value of false and then result is printed.
package com.tutorialspoint; public class BooleanDemo { public static void main(String[] args) { // create and assign values to String s1 String s1 = "Yes"; // create 1 boolean primitive bool1 boolean bool1; /** * static method is called using class name * apply result of parseBoolean on s1 to bool1 */ bool1 = Boolean.parseBoolean(s1); String str1 = "Parse boolean on " + s1 + " gives " + bool1; // print b1 value System.out.println( str1 ); } }
Output
Let us compile and run the above program, this will produce the following result −
Parse boolean on Yes gives false
Parsing a null String Value as false Boolean Example
The following example shows the usage of Boolean parseBoolean() method for a null string. In this program, we've a null String and using parseBoolean() method, we're parsing the null string to a primitive boolean value of false and then result is printed.
package com.tutorialspoint; public class BooleanDemo { public static void main(String[] args) { // create a String variable s1 String s1 = null; // create 1 boolean primitive bool1 boolean bool1; /** * static method is called using class name * apply result of parseBoolean on s1 to bool1 */ bool1 = Boolean.parseBoolean(s1); String str1 = "Parse boolean on " + s1 + " gives " + bool1; // print b1 value System.out.println( str1 ); } }
Output
Let us compile and run the above program, this will produce the following result −
Parse boolean on null gives false