- We will get list of all environment variables using System class.
- We will iterate through the map of system variables using java8 streams.
1. Program – print all environment variables using java8 streams.
package org.learn;
import java.util.Map;
import java.util.Properties;
public class ListEnvironmentVariables {
public static void main(String[] args) {
Map<String, String> mapEnvVariables = System.getenv();
System.out.println("Environment variables are as follows:");
mapEnvVariables.forEach(
(key,value)
->
System.out.println(key + " = " +value)
);
}
}
2. Output – list of all environment variables using java8 streams.
Environment variables are as follows:
CATALINE_HOME = E:\apache-tomcat-8.0.23
PROCESSOR_LEVEL = 6
FPS_BROWSER_APP_PROFILE_STRING = Internet Explorer
LOGONSERVER = \\BWIND-DC1
ACTIVATOR_HOME = E:\Software\activator-1.2.8-minimal
JAVA_HOME = C:\Program Files\Java\jdk1.8.0_101
SESSIONNAME = Console
ALLUSERSPROFILE = C:\ProgramData
PROCESSOR_ARCHITECTURE = AMD64
SystemDrive = C:
JETTY_HOME = E:\jetty-distribution-9.3.1.v20150714
USERNAME = admin
TOMCAT_HOME = E:\apache-tomcat-8.0.23
ProgramFiles(x86) = C:\Program Files (x86)
CommonProgramFiles = C:\Program Files\Common Files
Path = C:\ProgramData\Oracle\Java\javapath;C:\Windows\system32
FPS_BROWSER_USER_PROFILE_STRING = Default
PATHEXT = .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
OS = Windows_NT
COMPUTERNAME = 2YR1L72
PLAY2_HOME = E:\Software\activator-1.2.8-minimal
PROCESSOR_REVISION = 5e03
CommonProgramW6432 = C:\Program Files\Common Files
ComSpec = C:\Windows\system32\cmd.exe
UATDATA = C:\Windows\CCM\UATData\D9F8C395-CAB8-491d-B8AC-179A1FE1BE77
ProgramData = C:\ProgramData
SystemRoot = C:\Windows
HOMEDRIVE = C:
PROCESSOR_IDENTIFIER = Intel64 Family 6 Model 94 Stepping 3, GenuineIntel
CommonProgramFiles(x86) = C:\Program Files (x86)\Common Files
ProgramFiles = C:\Program Files
PUBLIC = C:\Users\Public
NUMBER_OF_PROCESSORS = 8
windir = C:\Windows