Java tutorial
//package com.java2s; import java.util.Map; public class Main { public static String getStringByMap(Map<String, Object> map) { StringBuffer sb = new StringBuffer(100); for (Map.Entry<String, Object> m : map.entrySet()) { String key = m.getKey(); Object value = m.getValue(); if (value != null) { String clsName = value.getClass().getName(); if (value.getClass().isArray()) sb.append("[").append(key).append(":").append("ARRAY").append(":") .append(toStringByArray((Object[]) value)).append("]"); else if ((("java.lang.String".equals(clsName)) || ("java.lang.Integer".equals(clsName)) || ("java.lang.Long".equals(clsName)) || ("java.lang.Boolean".equals(clsName)) || ("java.util.Date".equals(clsName))) && (!"".equals(value.toString()))) { sb.append("[").append(key).append(":").append(value.getClass().getName()).append(":") .append(esc(value.toString())).append("]"); } } } return sb.toString(); } private static String toStringByArray(Object[] value) { StringBuffer sb = new StringBuffer(100); String type = value[0].getClass().getName(); sb.append("{").append(type).append("@"); for (int i = 0; i < value.length; i++) { sb.append(esc(value[i].toString())).append(","); } return sb.substring(0, sb.length() - 1) + "}"; } private static String esc(String str) { return str.replaceAll(":", "&&&").replaceAll("\\[", "&!&").replaceAll("\\]", "!&!").replaceAll(",", "!!!") .replaceAll("\\{", "!!&").replaceAll("\\}", "&&!").replaceAll("@", "###"); } }