The Boolean.parseBoolean(String s) method is used to parse 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".
public class BooleanClassExample {
public static void main(String[] args) {
parseBoolean();
}
private static void parseBoolean() {
// parsing different Strings
boolean b1 = Boolean.parseBoolean("True");
boolean b2 = Boolean.parseBoolean("TruE");
boolean b3 = Boolean.parseBoolean("False");
boolean b4 = Boolean.parseBoolean("FALSE");
boolean b5 = Boolean.parseBoolean("source code examples");
System.out.println(b1);
System.out.println(b2);
System.out.println(b3);
System.out.println(b4);
System.out.println(b5);
}
}
Output:
true
true
false
false
false
Reference
Boolean
Java
Comments
Post a Comment