Java Properties to Map toMap(Properties sourceProperties)

Here you can find the source of toMap(Properties sourceProperties)

Description

Make a Map<String, String> from the supplied Properties, copying all the keys and values.

License

Open Source License

Parameter

Parameter Description
sourceProperties Properties representing properties key-value map.

Return

a Map<String, String> representation of the source Properties.

Declaration

public static Map<String, String> toMap(Properties sourceProperties) 

Method Source Code


//package com.java2s;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;

public class Main {
    /**//  w w w.  j  ava 2s . c o m
     * Make a Map&lt;String, String&gt; from the supplied Properties,
     * copying all the keys and values.
     *
     * @param sourceProperties Properties representing properties key-value map.
     * @return a Map&lt;String, String&gt; representation of the source
     *          Properties.
     */
    public static Map<String, String> toMap(Properties sourceProperties) {
        if (sourceProperties == null) {
            return null;
        }
        Map<String, String> configMap = new HashMap<String, String>();
        Iterator<?> iter = sourceProperties.keySet().iterator();
        while (iter.hasNext()) {
            String key = (String) iter.next();
            configMap.put(key, sourceProperties.getProperty(key));
        }
        return configMap;
    }
}

Related

  1. toMap(Properties props)
  2. toMap(Properties props)
  3. toMap(Properties props)
  4. toMap(Properties props)
  5. toMap(Properties props, String prefix)