In this tutorial we will learn how to convert a string type data to boolean type data.
In this tutorial we will learn how to convert a string type data to boolean type data.In this tutorial we will learn how to convert a string type data to boolean type data.
This program will take a String value from mystring variable. The line boolean mybool = Boolean.parseBoolean(mystring); converts the mystring string type value to mybool boolean type value. The parseBoolean() method coverts any type data to boolean type data.
class Stringtoboolean {
public static void main(String[] args) {
try {
String mystring = "true";
boolean mybool = Boolean.parseBoolean(mystring);
System.out.println("Converted value from String to boolean is: "
+ mybool);
} catch (Exception e) {
System.out.println(" Error " + e);
}
}
};
