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.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Use Boolean.valueOf(String string) to archieve your goal.
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 typebooleaninstead of the boxed typeBooleanto spare some CPU cycles in most cases.