Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Boolean.getBoolean("true") returns false

Tags:

java

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?

like image 248
vico Avatar asked Jan 28 '14 16:01

vico


People also ask

How do you use getBoolean?

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.

What is boolean parseBoolean in Java?

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.

Is there a boolean object in Java?

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.

Are booleans case sensitive in Java?

The case of the property name itself is case sensitive, but its value ("true", "TRUE", "trUE", "TRue", etc.) is case insensitive.


2 Answers

Boolean.getBoolean()'s argument expects the name of a system property. What you're looking for is Boolean.valueOf("true")

like image 65
Zach Thacker Avatar answered Sep 22 '22 13:09

Zach Thacker


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().

like image 29
rhobincu Avatar answered Sep 22 '22 13:09

rhobincu