Convert Java String Object to Boolean Object

A string object can be created in Java using the string literal.

String myStr = “Amit”;

Another way to create a string object is using the new keyword.

String myStr = new String("Hello!");

We have used the first method to create a string object.

String str = "true";

Now, use the valueOf() method to convert String Object to Boolean Object. We have used this method on Boolean object.

Boolean bool = Boolean.valueOf(str);

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


 Live Demo

public class Demo {
   public static void main(String[] args) {
      String str = "true";
      // conversion
      Boolean bool = Boolean.valueOf(str);



Updated on: 26-Jun-2020

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started