Get Environment Variables in Java

Description

The following code shows how to get Environment Variables.

Example


/*www  . ja va  2  s.  c  om*/
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

public class Main {
  public static void main(String[] args) {
    Map map = System.getenv();

    Set keys = map.keySet();
    Iterator iterator = keys.iterator();
    while (iterator.hasNext()) {
      String key = (String) iterator.next();
      String value = (String) map.get(key);

      System.out.println(key + " = " + value);
    }
  }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    Development »




Java Algorithms
Java Clipboard
Java Compiler
Java Desktop
Java Virtual Machine
Java Math
OS
Random
Java Robot
Java RuntimeMXBean
Java Timer
Java UUID
Java Internationalization