I am surprised to know that getBoolean() and valueOf() method returns different results for the same input string.
getBoolean()
valueOf()
I have tried to pass the "true" to both the methods. But getBoolean() gives me false output whereas valueOf() gives me right output that is true. Why?
"true"
The API-documentation is your friend.
Boolean.getBoolean probably doesn't do what you think it does:
Boolean.getBoolean
Returns true if and only if the system property named by the argument exists and is equal to the string "true".
Boolean.valueOf is probably what you're looking for:
Boolean.valueOf
The Boolean returned represents the value true if the string argument is not null and is equal, ignoring case, to the string "true".
2.1m questions
2.1m answers
60 comments
57.0k users