To convert
String
to boolean
in Java, use Boolean.parseBoolean
.Here's how you do it:
String trueString = "true";
String falseString = "false";
String textString = "Hello World!";
System.out.println(Boolean.parseBoolean(trueString)); // true
System.out.println(Boolean.parseBoolean(falseString)); // false
System.out.println(Boolean.parseBoolean(textString)); // false