Java Map to Properties mapToProperties(Map propertyMap)

Here you can find the source of mapToProperties(Map propertyMap)

Description

Convert string of comma separated properties to a map.

License

Apache License

Parameter

Parameter Description
properties a parameter

Declaration

public static String mapToProperties(Map<String, Object> propertyMap) 

Method Source Code

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

import java.util.Map;

public class Main {
    /**/*from w w  w.  jav a2  s.  c o  m*/
     * Convert string of comma separated properties to a map.
     * 
     * <p>
     * Any value will be converted by default to string using {@link #toString()}.
     * </p>
     * 
     * @param properties
     */
    public static String mapToProperties(Map<String, Object> propertyMap) {
        StringBuilder propertyBuilder = new StringBuilder();
        boolean hasAtLeastOneKey = false;
        for (String key : propertyMap.keySet()) {
            if (hasAtLeastOneKey) {
                propertyBuilder.append(", ");
            }
            if (!key.isEmpty()) {
                hasAtLeastOneKey = true;
                propertyBuilder.append(key);
                if (propertyMap.get(key) != null) {
                    propertyBuilder.append("=").append(propertyMap.get(key).toString().trim());
                }
            }
        }
        return propertyBuilder.toString();
    }
}

Related

  1. mapToProperties(Map params)
  2. mapToProperties(Map map)