- 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 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
Example 1
The following example shows the usage of Boolean parseBoolean() method for a string value as true.
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
Example 2
The following example shows the usage of Boolean parseBoolean() method for a a string value as Yes.
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
Example 3
The following example shows the usage of Boolean parseBoolean() method for a a string as null.
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