Java Basic Examples

Java convert String to boolean example

This example shows how to convert Java String to boolean in Java. This example also shows how to convert String to boolean primitive using Boolean wrapper class.

How to convert String to boolean in Java?

To convert String to boolean, use parseBoolean method of Java Boolean wrapper class.

This method returns boolean primitive value by parsing the input String value.


Important Note:

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

Here are some of the example String values and their possible boolean output.

Please note that, parseBoolean returns “false” boolean value even for the empty String value (“”) and null.

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