Get all system properties and return as Map<String, String> - Android java.lang

Android examples for java.lang:System

Description

Get all system properties and return as Map<String, String>

Demo Code

import java.util.Collections;
import java.util.Enumeration;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Vector;

public class Main{

    public static Map<String, String> getSystemProperties() {
        Properties p = System.getProperties();
        Enumeration<Object> keys = p.keys();
        List<String> listKeys = new Vector<String>();

        while (keys.hasMoreElements()) {
            String key = (String) keys.nextElement();
            listKeys.add(key);/*from   ww  w  .ja v a2  s  .  co  m*/
        }

        Collections.sort(listKeys);

        Map<String, String> mapProperties = new LinkedHashMap<String, String>();

        for (int i = 0; i < listKeys.size(); i++) {
            String key = listKeys.get(i);
            String value = p.getProperty(key);

            mapProperties.put(key, value);
        }

        return mapProperties;
    }

}

Related Tutorials