Java Program to convert String to Boolean

Java 8Object Oriented ProgrammingProgramming

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
raja
Published on 13-Nov-2018 05:30:04
Advertisements