English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Convert Java String Object to Boolean Object

String objects can be created in Java using string literals.

String myStr = "Amit";

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

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

We use the first method to create a string object.

String str = "true";

Now, using thevalueOf()The method converts a string object to a boolean object. We have already used this method on a boolean object.

Boolean bool = Boolean.valueOf(str);

Now let's see the complete example to show how to convert a String Object to a Boolean Object.

Example

public class Demo {
   public static void main(String[] args) {
      String str = "true";
      //Conversion
      Boolean bool = Boolean.valueOf(str);
      System.out.println(bool);
   }
}

Output Result

True