Pages

System.getenv() in Java?\

System.getenv() in Java?

System.getenv():
  • It will return all the system environment variables
  • System.getenv() method return type is Map<String,String>
Demo program on System.getenv():
public class EnvVariables {
    public static void main(String args[]) {
        System.out.println(System.getenv());
    }
}
Output:
getenv()
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:
getenv()
System.getenv()
Please comment below to feedback or ask questions.

No comments:

Post a Comment

Please comment below to feedback or ask questions.