Java Map Copy copyPropertiesToMap(Properties source, Map target)

Here you can find the source of copyPropertiesToMap(Properties source, Map target)

Description

This function copies all mappings from source properties to target map.

License

Apache License

Parameter

Parameter Description
source The source properties
target The target map to populate

Declaration

public static void copyPropertiesToMap(Properties source,
        Map<String, String> target) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

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

public class Main {
    /**/*w  w  w .ja v a 2 s  . c  o m*/
     * This function copies all mappings from source properties to target map.
     * 
     * @param    source
     *          The source properties
     * @param    target
     *          The target map to populate
     */
    public static void copyPropertiesToMap(Properties source,
            Map<String, String> target) {
        if (source != null) {
            //convert to map
            Iterator<Entry<Object, Object>> iterator = source.entrySet()
                    .iterator();
            Entry<Object, Object> entry = null;
            String key = null;
            String value = null;
            while (iterator.hasNext()) {
                //get next entry
                entry = iterator.next();

                //get next key/value
                key = (String) entry.getKey();
                value = (String) entry.getValue();

                //put in map
                target.put(key, value);
            }
        }
    }
}

Related

  1. copyOf(final Map map)
  2. copyOf(Map src)
  3. copyOnWritePut(K k, V v, Map source)
  4. copyOptions(Map options)
  5. copyParameters(Map parameters)
  6. copySafelyToObjectToObjectMap(java.util.Map map)
  7. copyStringMap(Map initParams)
  8. copyUntilFull(final Map source, final Map dest1, Map overflow, final int dest1Capacity)
  9. copyValue(Map source, Map target, K key)