System.getenv() in Java?
System.getenv():
System.getenv():
- It will return all the system environment variables
- System.getenv() method return type is Map<String,String>
public class EnvVariables {
public static void main(String args[]) {
System.out.println(System.getenv());
}
}
Output:
System.getenv() |
Get required environment variable value:
import java.util.Map;
public class EnvVariables {
public static void main(String args[]) {
Map envVariables = System.getenv();
System.out.println("System Environment Variables=" + envVariables);
System.out.println("Get specific environment variable using map=" + envVariables.get("JAVA_HOME"));
System.out.println("Get specific environment variable directly="+System.getenv("JAVA_HOME"));
}
}
Output:
System.getenv()
Please comment below to feedback or ask questions.
No comments:
Post a Comment
Please comment below to feedback or ask questions.