I am wondeirng how to print out all the system variables. I would like to know if I can enumerate them all.
4 Answers
Do you mean like?
System.getProperties().list(System.out);
or
for (Map.Entry<Object, Object> entry : System.getProperties().entrySet())
System.out.println(entry);

- 525,659
- 79
- 751
- 1,130
-
when I use System.getProperties().list(System.out) why some item are displayed as *****...? – user705414 Nov 23 '11 at 13:15
-
also, have a warning here Map.Entry entry Map.Entry is a raw type – user705414 Nov 23 '11 at 13:18
-
list() truncates long values, which is why printing the entries yourself might be advisable. – Peter Lawrey Nov 23 '11 at 13:22
-
I have changed the code so it doesn't produce a warning. Its a bit meaningless given the keys and values are all String not Object. ;) – Peter Lawrey Nov 23 '11 at 13:23
System.getProperties()
is what you're after - you can then enumerate through those. You can call the values()
or propertyNames()
methods on the returned property object depending on whether it's the names or the values that you're after (or of course the entrySet()
for both.)
Alternatively you can use the list()
method directly if all you want to do is print them out somewhere.

- 70,193
- 21
- 157
- 216
There are 3 places where you can find a kind of system or environment variables.
- System.getProperties()
- System.getenv()
- various properties of RuntimeMBean that can be accessible using
ManagementFactory.getRuntimeMXBean()

- 114,158
- 16
- 130
- 208
You can use SqlTool to list all or a specified Java system property on the command line. No Java SDK or coding required.
Download the SqlTool jar file by clicking on the Download "jar" link on this Maven repository page.
You can then dump all Java system properties with:
java -jar path/to/sqltool-VERSION.jar --sql "*listsysprops"
To list a specific system property value, just add it after 'listsysprops', like
java -jar path/to/sqltool-VERSION.jar --sql "*listsysprops user.home"

- 1,577
- 2
- 17
- 15