Skip to content

Java convert String to boolean example

This example shows how to convert string to boolean in Java using the parseBoolean method of the Boolean wrapper class including the empty and null values.

How to convert String to boolean in Java?

To convert a string to a boolean primitive value, use the parseBoolean method of the Java Boolean wrapper class.

This method returns a boolean primitive value by parsing the input string value.

Output

Important Note:

The parseBoolean method returns true if the string value is not null and contains “true” ignoring the case. For every other value, the parseBoolean method returns a false boolean value.

Here are some of the example string values and their possible boolean outputs.

Please note that the parseBoolean method returns a false boolean value even for an empty string value (“”) and a null value.

This example is a part of the Java Basic Examples and Java Type conversion Tutorial.

Please let me know your views in the comments section below.

About the author

Leave a Reply

Your email address will not be published.