<< Pretty Printed Code Listings in Cygwin | Home | $249 IntelliJ IDEA Personal License >>

Boolean.getBoolean()

Quickly, what is printed by the following line of Java code?

    System.out.println(Boolean.getBoolean("true"));


Re: Boolean.getBoolean()

false System property hack etc etc.

Re: Boolean.getBoolean()

false unless you got a system property named "true" defined with the value "true", "T" or "1".

Re: Boolean.getBoolean()

No, "T" or "1" becomes false. The value has to be "true" or a case insensitive variant of it, such as "True", "TRUE", or "TRUe", even if the default Locale is not an English one.

Re: Boolean.getBoolean()

The last comment is correct. The code becomes more obvious when you write it like this:
boolean isTestMode = Boolean.getBoolean("com.mycompany.istestmode");

It looks for a system property named "com.mycompany.istestmode" and returns true if that system property equals "true", "TRUE", "tRUE", etc...


Add a comment Send a TrackBack