Here you can find the source of mapToString(Map
private static String mapToString(Map<String, String[]> parameterMap)
//package com.java2s; //License from project: Apache License import java.util.Arrays; import java.util.Iterator; import java.util.Map; public class Main { private static String mapToString(Map<String, String[]> parameterMap) { StringBuilder sb = new StringBuilder().append('['); for (Map.Entry<String, String[]> entry : parameterMap.entrySet()) { sb.append(entry.getKey()).append(" -> "); String[] value = entry.getValue(); if (value != null) { sb.append("("); appendTo(sb, Arrays.asList(value), ","); sb.append(")"); }/* w w w . j a v a 2s.co m*/ sb.append(','); // I know being lazy } return sb.append(']').toString(); } private static StringBuilder appendTo(StringBuilder appendable, Iterable<?> parts, CharSequence separator) { Iterator<?> iterator = parts.iterator(); if (iterator.hasNext()) { appendable.append(toString(iterator.next())); while (iterator.hasNext()) { appendable.append(separator); appendable.append(toString(iterator.next())); } } return appendable; } private static CharSequence toString(Object part) { return (part instanceof CharSequence) ? (CharSequence) part : part .toString(); } }