Converts a Properties object into a Map. - Java java.util

Java examples for java.util:Properties File

Description

Converts a Properties object into a Map.

Demo Code


//package com.book2s;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

public class Main {
    /**//from  w  ww .  java 2 s.  c o m
     * Converts a Properties object into a Map.
     * 
     * @param properties
     *            set of string key-value pairs
     * @returns map of key-value pairs (never null)
     */
    public static Map<String, String> getMapFromProperties(Properties props) {
        Map<String, String> map = new HashMap<String, String>();

        if (props != null) {
            Enumeration<Object> e = props.keys();
            while (e.hasMoreElements()) {
                String s = (String) e.nextElement();
                map.put(s, props.getProperty(s));
            }
        }

        return map;
    }
}

Related Tutorials