Java Properties to Map toMap(Properties properties)

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

Description

Returns a Map<String, String> out of a Java Properties object.

License

Apache License

Parameter

Parameter Description
properties the properties object to convert

Return

Java Map corresponding to the Java Properties object.

Declaration

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

Method Source Code

//package com.java2s;
/*//ww w .ja  v  a 2 s . c  o  m
 * ========================================================================
 *
 * Codehaus CARGO, copyright 2004-2011 Vincent Massol, 2012-2018 Ali Tokmen.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * ========================================================================
 */

import java.util.HashMap;

import java.util.Map;
import java.util.Properties;

public class Main {
    /**
     * Returns a <code>Map&lt;String, String&gt;</code> out of a Java Properties object.
     * 
     * @param properties the properties object to convert
     * @return Java Map corresponding to the Java Properties object.
     */
    public static Map<String, String> toMap(Properties properties) {
        Map<String, String> result = new HashMap<String, String>(properties.size());
        for (Map.Entry<Object, Object> parameter : properties.entrySet()) {
            String value = null;
            if (parameter.getValue() != null) {
                value = parameter.getValue().toString();
            }
            result.put(parameter.getKey().toString(), value);
        }
        return result;
    }
}

Related

  1. toMap(Properties properties)
  2. toMap(Properties properties)
  3. toMap(Properties properties)
  4. toMap(Properties properties)
  5. toMap(Properties properties)
  6. toMap(Properties properties)
  7. toMap(Properties props)
  8. toMap(Properties props)
  9. toMap(Properties props)