Java Utililty Methods Map to String

List of utility methods to do Map to String

Description

The list of methods to do Map to String are organized into topic(s).

Method

StringtoString(Map map)
Like Java Map.toString() but no curly braces
if (map == null)
    return "null";
StringBuilder sb = new StringBuilder(map.size() * 128);
Set<String> keys = map.keySet();
Iterator<String> it = keys.iterator();
while (it.hasNext()) {
    String key = it.next();
    Object value = map.get(key);
...
StringtoString(Map map)
to String
Iterator<? extends Map.Entry<String, ? extends Object[]>> iter = map.entrySet().iterator();
if (!iter.hasNext()) {
    return "{}";
StringBuilder sb = new StringBuilder();
sb.append('{');
while (true) {
    Map.Entry<String, ? extends Object[]> entry = iter.next();
...
StringtoString(Map attrs)
to String
if (attrs == null) {
    return "NULL";
StringBuffer buf = new StringBuffer(128);
List<String> keys = new ArrayList<String>(attrs.keySet());
Collections.sort(keys);
buf.append("{");
for (int i = 0; i < keys.size(); i++) {
...
StringtoString(Map attrs)
to String
StringBuilder sb = new StringBuilder();
if (null != attrs && !attrs.isEmpty()) {
    sb.append(SP);
    for (String key : attrs.keySet()) {
        String val = attrs.get(key);
        if (isNotEmpty(val)) {
            sb.append(encode(key)).append(SSP).append(encode(val)).append(SP);
return sb.toString();
StringtoString(Map m)
to String
if (m.isEmpty()) {
    return "";
StringBuilder sb = new StringBuilder();
int n = m.size();
for (String key : m.keySet()) {
    sb.append("\"" + key + "\"" + K_V_SEPARATOR + "\"" + m.get(key) + "\"");
    if (n > 1) {
...
StringtoString(Map map)
Returns a string representation of the contents of the specified Map The string representation consists of a list of the Map's entries, enclosed in square brackets ("[]").
StringBuilder string = new StringBuilder("[");
for (Map.Entry<String, String> keyValue : map.entrySet()) {
    string.append(keyValue.getKey()).append(" = ").append(keyValue.getValue()).append(";");
return string.append("]").toString();
StringtoString(Map params)
to String
String str = "";
for (String key : params.keySet())
    str += key + "[" + params.get(key) + "] ";
return str.isEmpty() ? "empty" : str;
StringtoString(Map map)
to String
StringBuilder sb = new StringBuilder();
boolean first = true;
for (Map.Entry<String, String[]> entry : map.entrySet()) {
    if (first == false) {
        sb.append(",");
    } else {
        first = false;
    sb.append(entry.getKey() + "={");
    boolean innerFirst = true;
    for (String value : entry.getValue()) {
        if (innerFirst == false) {
            sb.append(",");
        } else {
            innerFirst = false;
        sb.append(value);
    sb.append("}");
return sb.toString();
voidtoString(Map map, StringBuilder sb)
to String
sb.append('{');
for (Iterator<Map.Entry<String, String[]>> i = map.entrySet().iterator(); i.hasNext();) {
    Map.Entry<String, String[]> entry = i.next();
    sb.append(entry.getKey()).append('=').append('[');
    String[] value = entry.getValue();
    for (int j = 0; j < value.length; j++) {
        if (j > 0) {
            sb.append(',');
...
MaptoStringMap(Map enumMap)
to String Map
Map<String, T> map = new HashMap<String, T>(enumMap.size(), 1f);
for (E e : enumMap.keySet()) {
    map.put(e.name(), enumMap.get(e));
return map;