convert Properties to Map<String,String> - Java java.util

Java examples for java.util:Properties File

Description

convert Properties to Map<String,String>

Demo Code


//package com.java2s;

import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.Set;

public class Main {
    public static Map<String, String> convert(Properties props) {
        Map<String, String> _result = new HashMap<String, String>();
        Set<Entry<Object, Object>> propsSet = props.entrySet();
        for (Entry<Object, Object> p : propsSet) {
            Object value = p.getValue();
            if (value == null) {
                _result.put(p.getKey().toString(), null);
            } else {
                _result.put(p.getKey().toString(), value.toString());
            }/*w  w  w .  j  a  va 2 s . com*/
        }
        return _result;
    }
}

Related Tutorials