getBoolean(String str) and valueOf(String str) of Boolean class gives different output

后端 未结 5 1952
野性不改
野性不改 2020-12-29 18:38

I am surprised to know that getBoolean() and valueOf() method returns different results for the same input string.

I have tried to pass the

5条回答
  •  攒了一身酷
    2020-12-29 19:16

                                         The API-documentation is your friend.

    • Boolean.getBoolean probably doesn't do what you think it does:

      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:

      The Boolean returned represents the value true if the string argument is not null and is equal, ignoring case, to the string "true".

提交回复
热议问题