Java Map Print printHashMap(String lt, HashMap map, String rt, int maxparm)

Here you can find the source of printHashMap(String lt, HashMap map, String rt, int maxparm)

Description

print Hash Map

License

Open Source License

Parameter

Parameter Description
lt a parameter
map a parameter
rt a parameter
maxparm a parameter

Declaration

public static int printHashMap(String lt, HashMap<String, String> map, String rt, int maxparm) 

Method Source Code

//package com.java2s;

import java.util.HashMap;
import java.util.Iterator;

import java.util.Set;

public class Main {
    /**//w ww .  j  ava  2 s. c  o  m
     * @param lt
     * @param map
     * @param rt
     * @param maxparm
     * @return
     */
    public static int printHashMap(String lt, HashMap<String, String> map, String rt, int maxparm) {
        Set<String> keySetOfPaths = map.keySet();
        Iterator<String> itrKeySetOfPaths = keySetOfPaths.iterator();

        int maxlen = maxparm;

        while (itrKeySetOfPaths.hasNext()) {
            String aKey = itrKeySetOfPaths.next();
            if (maxlen < aKey.length())
                maxlen = aKey.length();
        }

        keySetOfPaths = map.keySet();
        itrKeySetOfPaths = keySetOfPaths.iterator();

        while (itrKeySetOfPaths.hasNext()) {
            String aKey = itrKeySetOfPaths.next();
            String aVal = map.get(aKey);

            int gap = maxlen - aKey.length();

            System.out.print(lt + aKey);

            for (int i = 0; i < gap; i++)
                System.out.print(" ");

            System.out.println(" , " + aVal + rt);
        }

        return maxlen;
    }

    /**
     * @param map
     */
    public static void printHashMap(HashMap<String, String> map) {
        Set<String> keySetOfPaths = map.keySet();
        Iterator<String> itrKeySetOfPaths = keySetOfPaths.iterator();

        int maxlen = 0;

        while (itrKeySetOfPaths.hasNext()) {
            String aKey = itrKeySetOfPaths.next();
            if (maxlen < aKey.length())
                maxlen = aKey.length();
        }

        keySetOfPaths = map.keySet();
        itrKeySetOfPaths = keySetOfPaths.iterator();

        while (itrKeySetOfPaths.hasNext()) {
            String aKey = itrKeySetOfPaths.next();
            String aVal = map.get(aKey);

            int gap = maxlen - aKey.length();

            System.out.print("-> " + aKey);

            for (int i = 0; i < gap; i++)
                System.out.print(" ");

            System.out.println(" , " + aVal);
        }
    }

    /**
     * @param lt
     * @param map
     * @param rt
     * @return
     */
    public static int printHashMap(String lt, HashMap<String, String> map, String rt) {
        Set<String> keySetOfPaths = map.keySet();
        Iterator<String> itrKeySetOfPaths = keySetOfPaths.iterator();

        int maxlen = 0;

        while (itrKeySetOfPaths.hasNext()) {
            String aKey = itrKeySetOfPaths.next();
            if (maxlen < aKey.length())
                maxlen = aKey.length();
        }

        keySetOfPaths = map.keySet();
        itrKeySetOfPaths = keySetOfPaths.iterator();

        while (itrKeySetOfPaths.hasNext()) {
            String aKey = itrKeySetOfPaths.next();
            String aVal = map.get(aKey);

            int gap = maxlen - aKey.length();

            System.out.print(lt + aKey);

            for (int i = 0; i < gap; i++)
                System.out.print(" ");

            System.out.println(" , " + aVal + rt);
        }

        return maxlen;
    }
}

Related

  1. printHash(HashMap hashMap)
  2. printHash(HashMap hashMap)
  3. printHeaders(Map> headers)
  4. printHttpMessage(String statusLine, Map headers)
  5. printItems(HashMap map)
  6. printKeys(Map m)