Java examples for java.lang:System
Prints the system properties as [key: name].
/*/*from w ww .j ava 2 s .c o m*/ * MiscUtils.java * * Copyright (C) 2002-2013 Takis Diakoumis * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 3 * of the License, or any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ //package com.java2s; import java.util.Arrays; import java.util.Enumeration; import java.util.Properties; public class Main { /** * Prints the system properties as [key: name]. */ public static void printSystemProperties() { String[][] properties = getSystemProperties(); for (int i = 0; i < properties.length; i++) { System.out.println(properties[i][0] + ":\t" + properties[i][1]); } } /** * Returns the system properties from <code>System.getProperties()</code> * as a 2 dimensional array of key/name. */ public static String[][] getSystemProperties() { Properties sysProps = System.getProperties(); String[] keys = new String[sysProps.size()]; int count = 0; for (Enumeration<?> i = sysProps.propertyNames(); i .hasMoreElements();) { keys[count++] = (String) i.nextElement(); } Arrays.sort(keys); String[][] properties = new String[keys.length][2]; for (int i = 0; i < keys.length; i++) { properties[i][0] = keys[i]; properties[i][1] = sysProps.getProperty(keys[i]); } return properties; } }