Java Program to convert String to Boolean


To convert String to Boolean, use the parseBoolean() method in Java. The parseBoolean() parses the string argument as a boolean. The boolean returned represents the value true if the string argument is not null and is equal, ignoring case, to the string "true".

Firstly, declare a string.

String str = "false";

Now, use the Boolean.parseBoolean() method to convert the above declared String to Boolean.

boolean bool = Boolean.parseBoolean(str);

Let us now see the complete example to learn how to convert String to Boolean.

Example

 Live Demo

public class Demo {
   public static void main(String[] args) {
      // string
      String str = "false";
      // string to boolean
      boolean bool = Boolean.parseBoolean(str);
      // returned boolean value
      System.out.println(bool);
   }
}

Output

false

Samual Sam
Samual Sam

Learning faster. Every day.

Updated on: 26-Jun-2020

15K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements