Here you can find the source of printMapGeneral(Map
public static void printMapGeneral(Map<String, ?> map)
//package com.java2s; import java.util.Iterator; import java.util.Map; public class Main { /** @METHOD */ public static void printMapGeneral(Map<String, ?> map) { if (map == null || map.size() == 0) { System.out.println("**NO ITEM !!"); return; }/* w ww . j a v a2 s .c om*/ int max = 0; Iterator<String> itr; itr = map.keySet().iterator(); while (itr.hasNext()) { int x = itr.next().length(); if (x > max) max = x; } max += 0; itr = map.keySet().iterator(); int i = 0; while (itr.hasNext()) { String aKey = itr.next(); Object aVal = map.get(aKey); int len = aKey.length(); int gap = max - len; System.out.print(" " + ((i++) + 1) + ": " + aKey); for (int j = 0; j < gap; j++) System.out.print(" "); System.out.println(", " + aVal + ""); } } /** @METHOD */ public static void printMapGeneral(Map<String, ?> map, String suffix) { if (map == null || map.size() == 0) { System.out.println("**NO ITEM !!"); return; } int max = 0; Iterator<String> itr; itr = map.keySet().iterator(); while (itr.hasNext()) { int x = itr.next().length(); if (x > max) max = x; } max += 0; itr = map.keySet().iterator(); int i = 0; while (itr.hasNext()) { String aKey = itr.next(); Object aVal = map.get(aKey); int len = aKey.length(); int gap = max - len; System.out.print(" " + ((i++) + 1) + ": " + aKey); for (int j = 0; j < gap; j++) System.out.print(" "); System.out.println(", " + aVal + suffix); } } }