Java tutorial
//package com.java2s; import java.util.Iterator; import java.util.Map; import java.util.Map.Entry; import java.util.Set; public class Main { public static String hashMapToString(Map<? extends Object, ? extends Object> map) { Set<?> entrySet = map.entrySet(); Iterator<?> it = entrySet.iterator(); Map.Entry<? extends Object, ? extends Object> entry = null; StringBuilder strbldr = new StringBuilder(); strbldr.append("{ "); while (it.hasNext()) { entry = (Entry<? extends Object, ? extends Object>) it.next(); strbldr.append(entry.getKey() + ":" + entry.getValue() + ", "); } return new StringBuilder(strbldr.substring(0, strbldr.length() - 2)).append(" }").toString(); } }