Boolean.getBoolean () Vs System.getenv () in Java

Boolean.getBoolean("myvariable"); // where myvariable has been defined in the
                                  // Environment variable as Variable name:
                                  // myvariable
                                  // and Variable Value:true

The above call gives me an output like false. If i use

 System.getenv("myvariable") ; 

then he gives me a conclusion like true.

I wonder why it Boolean.getBoolean("myvariable")doesn't work.

+5
source share
2 answers

System.getenvreturns an environment variable. This is not the same as System.getPropertythat returned by the Java system property.

Boolean.getBoolean uses the last call as described:

Returns true if and only if the system property specified in the argument exists and is equal to the string "true". [...] A system property is available through getProperty, a method defined by the System class.

+11
source

Boolean.getBoolean("myvariable"); , myvariable, System.getenv("myvariable"); . , .

+3

All Articles