Java examples for Native OS:Environment
Iterating Through a Map of Environment Variables
import java.util.Map; public class Main { public static void main(String[] args){ if(args.length > 0){ String value = System.getenv(args[0]); if (value != null) { System.out.println(args[0].toUpperCase() + " = " + value); } else { System.out.println("No such environment variable exists"); } /* w ww . ja v a2 s .com*/ } else { Map<String, String> vars = System.getenv(); for(String var : vars.keySet()){ System.out.println(var + " = " + vars.get(var)); } } } }