Javatpoint Logo
Javatpoint Logo

Java Convert String to boolean

Java Convert String to boolean

We can convert String to boolean in java using Boolean.parseBoolean(string) method.

To convert String into Boolean object, we can use Boolean.valueOf(string) method which returns instance of Boolean class.

To get boolean true, string must contain "true". Here, case is ignored. So, "true" or "TRUE" will return boolean true. Any other string value except "true" returns boolean false.

Java String to boolean Example: Boolean.parseBoolean()

The parseBoolean() method converts string into boolean primitive.

The parseBoolean() is the static method of Boolean class. The signature of parseBoolean() method is given below:

Let's see the simple example of converting String to boolean in java.

Test it Now

Output:

true
true
false

Java String to Boolean Example: Boolean.valueOf()

The Boolean.valueOf() method converts string into Boolean object. Let's see the simple code to convert String to Boolean in java.

Test it Now

Output:

true
true
false




Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA