Java Map to String mapToString(Map map, String splitter)

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

Description

map To String

License

Apache License

Declaration

public static <T> String mapToString(Map<String, T> map, String splitter) 

Method Source Code

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

import java.util.*;

public class Main {
    public static <T> String mapToString(Map<String, T> map, String splitter) {
        if (map.size() == 0)
            return "";

        Iterator iterator = map.keySet().iterator();

        String key = (String) iterator.next();
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append(key);//w  w w . ja  v a  2 s  .  c  o m
        stringBuilder.append(":");
        stringBuilder.append(map.get(key));

        while (iterator.hasNext()) {
            key = (String) iterator.next();
            stringBuilder.append(splitter);
            stringBuilder.append(key);
            stringBuilder.append(":");
            stringBuilder.append(map.get(key));
        }
        return stringBuilder.toString();
    }

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

Related

  1. mapToString(Map map)
  2. mapToString(Map map)
  3. mapToString(Map map)
  4. mapToString(Map map)
  5. mapToString(Map parameterMap)
  6. mapToString(String aName, Map aMap, String aPrefix, String aSuffix, String aKeyValueSeparator, String anEntrySeparator, String anArrayPrefix, String anArraySuffix, String anArraySeparator, String anEscapeChars, char anEscapeSymbol)
  7. mapToString(String itemName, Map map)
  8. mapToStringArray(Map map)
  9. mapToStringBuilder(Map m)