Boolean.getBoolean("true") returns false
JavaJava Problem Overview
I'm trying to make function that reads ini file. Why Boolean.getBoolean("true")
returns false
? How to use this conversation in correct way in java 1.4? Does it depends on system settings?
Java Solutions
Solution 1 - Java
Boolean.getBoolean()
's argument expects the name of a system property. What you're looking for is Boolean.valueOf("true")
Solution 2 - Java
The method getBoolean takes a System Property name as an argument, not the String value of the boolean. What you need is probably Boolean.parseBoolean().
Solution 3 - Java
Boolean.getBoolean("true") has this javaDoc:
Returns true if and only if the system property named by the argument exists and is equal to the string "true". (Beginning with version 1.0.2 of the JavaTM platform, the test of this string is case insensitive.) A system property is accessible through getProperty, a method defined by the System class. If there is no property with the specified name, or if the specified name is empty or null, then false is returned.
You are looking for Boolean.valueOf("true")
Solution 4 - Java
From Boolean.getBoolean
>Returns true if and only if the system property named by the argument exists and is equal to the string "true".
(Beginning with version 1.0.2 of the JavaTM platform, the test of this string is case insensitive.)
A system property is accessible through getProperty, a method defined by the System class.
If there is no property with the specified name, or if the specified name is empty or null, then false is returned.
Solution 5 - Java
Try using Boolean.parseBoolean("true")