Boolean.getBoolean("true") returns false

Java

Java 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")

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionvicoView Question on Stackoverflow
Solution 1 - JavaZach ThackerView Answer on Stackoverflow
Solution 2 - JavarhobincuView Answer on Stackoverflow
Solution 3 - JavaSoccertrashView Answer on Stackoverflow
Solution 4 - JavaRakesh KRView Answer on Stackoverflow
Solution 5 - JavaEmad RazaviView Answer on Stackoverflow