String object to Boolean
java, type-conversion
Solution
Use Boolean.valueOf(String string) to archieve your goal.
boolean boolFlag = Boolean.valueOf(strFlag);
Returns a Boolean with a value represented by the specified String. The Boolean returned represents the value true if the string argument is not null and is equal, ignoring case, to the string "true".
Example: `Boolean.valueOf("True")` returns true.
Example: `Boolean.valueOf("yes")` returns false.
As of java 1.5 there's also `Boolean.parseBoolean(String s)` which returns the primitive type `boolean` instead of the boxed type `Boolean` to spare some CPU cycles in most cases.
Problem
When i tried to convert a String Object to boolean, the result is different. ``` String strFlag="true"; boolean boolFlag = Boolean.getBoolean(strFlag); ``` `boolFlag` ends up having a `false` value.