Java tutorial
//package com.java2s; /* * Copyright (c) 2012 - Batoo Software ve Consultancy Ltd. * * This copyrighted material is made available to anyone wishing to use, modify, * copy, or redistribute it subject to the terms and conditions of the GNU * Lesser General Public License, as published by the Free Software Foundation. * * 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 Lesser General Public License * for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this distribution; if not, write to: * Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ import java.util.Enumeration; import java.util.Map; import java.util.Properties; public class Main { /** * Merge the given Properties instance into the given Map, copying all properties (key-value pairs) over. * <p> * Uses <code>Properties.propertyNames()</code> to even catch default properties linked into the original Properties instance. * * @param props * the Properties instance to merge (may be <code>null</code>) * @param map * the target Map to merge the properties into */ @SuppressWarnings({ "unchecked", "rawtypes" }) public static void mergePropertiesIntoMap(Properties props, Map map) { if (map == null) { throw new IllegalArgumentException("Map must not be null"); } if (props != null) { for (final Enumeration<?> en = props.propertyNames(); en.hasMoreElements();) { final String key = (String) en.nextElement(); Object value = props.getProperty(key); if (value == null) { // Potentially a non-String value... value = props.get(key); } map.put(key, value); } } } }