Thanks to visit codestin.com
Credit goes to www.tutorialspoint.com

Convert String to Boolean in Java



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: Convert String to Boolean

 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
Updated on: 2024-06-21T13:09:42+05:30

16K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements