Here you can find the source of printVarTable(HashMap
Parameter | Description |
---|---|
map | a parameter |
public static void printVarTable(HashMap<String, ?> map)
//package com.java2s; import java.util.HashMap; import java.util.Iterator; public class Main { /**//from www.ja v a2 s . c o m * @param map */ public static void printVarTable(HashMap<String, ?> map) { int max = 0; Iterator<String> itr; /** * @ Calculate gap for printing. */ itr = map.keySet().iterator(); while (itr.hasNext()) { int x = itr.next().length(); if (x > max) max = x; } max += 3; itr = map.keySet().iterator(); /** * @ Print the map. */ while (itr.hasNext()) { String aKey = itr.next(); String aVal = map.get(aKey).toString(); int len = aKey.length(); int gap = max - len; System.out.print(" - " + aKey); for (int j = 0; j < gap; j++) System.out.print(" "); System.out.println(": " + aVal); } } }