Java Map Print printVarTable(HashMap map)

Here you can find the source of printVarTable(HashMap map)

Description

print Var Table

License

Open Source License

Parameter

Parameter Description
map a parameter

Declaration

public static void printVarTable(HashMap<String, ?> map) 

Method Source Code

//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);
        }
    }
}

Related

  1. printMapToString(Map map)
  2. printNERScore(Map scores)
  3. printOptions(Map options)
  4. printStringMap(Map hsMap, String sDel)
  5. printTokenStream(CommonTokenStream tokens, Map tokenToName)