How to convert String to boolean

In Java we have multiple ways to convert String to boolean. We will see a few of those ways in this post.

1. Convert String to boolean using Boolean.parseBoolean()

For Any value of string other than “true” (case insensitive), parseBoolean() will return false.


2. Convert String to boolean using Boolean.valueOf()

Similar to Boolean.parseBoolean(), we can convert String to Boolean using Boolean.valueOf().


Difference between Boolean.parseBoolean() and Boolean.valueOf()

The major difference between parseBoolean() and valueOf() is their return values.
parseBoolean will return primitive boolean, whereas valueOf() returns Boolean object.


1. Boolean API

It's only fair to share...Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn