I did a little search on this but couldn't find anything useful.
The point being that if String value is either "true" or "false" the return value should be true. In every other value it should be false.
I tried these:
String value = "false";
System.out.println("test1: " + Boolean.parseBoolean(value));
System.out.println("test2: " + Boolean.valueOf(value));
System.out.println("test3: " + Boolean.getBoolean(value));
All functions returned false :(
parseBoolean(String)
returns true if the String is (case-insensitive) "true", otherwise falsevalueOf(String)
ditto, returns the canonical Boolean ObjectsgetBoolean(String)
is a red herring; it fetches the System property of the given name and compares that to "true"There exists no method to test whether a String encodes a Boolean; for all practical effects, any input other than true
(ignoring case) returns false
.
Method | Returns |
---|---|
Boolean.parseBoolean( string ) |
primitive boolean |
Boolean.valueOf( string ) |
object Boolean |