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?
Boolean. getBoolean(String name) returns true if and only if the system property named by the argument exists and is equal to the string "true". A system property is accessible through getProperty, a method defined by the System class.
parseBoolean. public static boolean parseBoolean(String s) Parses the string argument as a boolean. 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.
Java For TestersThe Boolean class wraps a value of the primitive type boolean in an object. An object of type Boolean contains a single field whose type is boolean. static Boolean FALSE − This is the Boolean object corresponding to the primitive value false.
The case of the property name itself is case sensitive, but its value ("true", "TRUE", "trUE", "TRue", etc.) is case insensitive.
Boolean.getBoolean()
's argument expects the name of a system property. What you're looking for is Boolean.valueOf("true")
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().
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With