Querying Environment Variables by Ibrahim
On the Java platform, an application uses
System.getEnv
to retrieve environment variable values. Without an argument,
getEnv
returns a read-only instance of
java.util.Map
,
where the map keys are the environment variable names, and the map
values are the environment variable values. This is demonstrated in the
EnvMap
example:
import java.util.Map;
public class EnvMap {public class Env {
public static void main (String[] args) {
for (String env: args) {
String value = System.getenv(env);
if (value != null) {
System.out.format("%s=%s%n",
env, value);
} else {
System.out.format("%s is"
+ " not assigned.%n", env);
}
}
}
}
public static void main (String[] args) {
Map<String, String> env = System.getenv();
for (String envName
: env.keySet()) {
System.out.format("%s=%s%n",
envName,
env.get(envName));
}
}
javascript source code:
}