Convert 0 and 1 to boolean in Java

In this post, we will see how to convert 0 and 1 to Boolean in Java.

Given “0” and “1” in String datatype, convert it to boolean datatype where

“0” represents false
“1” represents true

Convert 0 and 1 to Boolean in Java

Here is program to convert 0 and 1 to boolean in Java

Output

In case, if you have integer values as 0 and 1, you can just make small change to getBoolean() method.

Output

Utility method to convert all possible values to boolean in Java

Here is simple utility method to convert all possible values to boolean in Java.

That’s all about how to convert 0 and 1 to boolean in Java.

Was this post helpful?

Leave a Reply

Your email address will not be published. Required fields are marked *