Java Map Print printMapGeneral(Map map)

Here you can find the source of printMapGeneral(Map map)

Description

print Map General

License

Open Source License

Declaration

public static void printMapGeneral(Map<String, ?> map) 

Method Source Code

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

Related

  1. printMap(Map map)
  2. printMap(Map map)
  3. printMap(Map map)
  4. printMap(Map map, int depth)
  5. printMap(String mapLabel, Map map)
  6. printMapObject(Map mapobject)
  7. printMapStrings(Map> map, String mapDescription)
  8. printMapToString(Map map)
  9. printNERScore(Map scores)