Here you can find the source of printHashMap(String lt, HashMap
Parameter | Description |
---|---|
lt | a parameter |
map | a parameter |
rt | a parameter |
maxparm | a parameter |
public static int printHashMap(String lt, HashMap<String, String> map, String rt, int maxparm)
//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; } }