Java Map to String mapToString(Map map)

Here you can find the source of mapToString(Map map)

Description

map To String

License

Open Source License

Declaration

public static String mapToString(Map<?, ?> map) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.Map;

public class Main {
    public static String mapToString(Map<?, ?> map) { //, String valueSeperator, String delimeter) {
        return mapToString(map, "=", ",");
    }/* www. ja v a  2  s.c  o  m*/

    public static String mapToString(Map<?, ?> map, String valueSeperator, String delimeter) {
        return mapToString(map, "", "", valueSeperator, delimeter);
    }

    public static String mapToString(Map<?, ?> map, String keyWrap, String valWrap, String valueSeperator,
            String delimeter) {
        StringBuilder text = new StringBuilder();
        for (Object key : map.keySet()) {
            Object value = map.get(key);
            text.append(keyWrap + key + keyWrap + valueSeperator + valWrap + value + valWrap + delimeter);
        }
        deleteLastDelimeter(text, delimeter);
        return text.toString();
    }

    public static void deleteLastDelimeter(StringBuilder sb, String delimeter) {
        if (sb.length() > delimeter.length()) {
            sb.delete(sb.length() - delimeter.length(), sb.length());
        }
    }
}

Related

  1. mapToString(Map map)
  2. mapToString(Map map)
  3. mapToString(Map map)
  4. mapToString(Map map)
  5. mapToString(Map map)
  6. mapToString(Map acs)
  7. mapToString(Map m)
  8. mapToString(Map map)
  9. mapToString(Map criteria)