Here you can find the source of printMap(String mapLabel, Map map)
Parameter | Description |
---|---|
mapLabel | Label for map. |
map | The map to print. <p> N.B. This method assumes both the keys and values have toString() methods. </p> |
public static void printMap(String mapLabel, Map map)
//package com.java2s; /* Please see the license information at the end of this file. */ import java.util.*; public class Main { /** Debugging support -- Print contents of a map (HashMap, TreeMap, etc.). *// w w w .ja v a 2 s .c om * @param mapLabel Label for map. * * @param map The map to print. * * <p> * N.B. This method assumes both the keys and values have toString() methods. * </p> */ public static void printMap(String mapLabel, Map map) { if (map == null) { System.out.println(mapLabel + " is null."); } else if (map.size() == 0) { System.out.println(mapLabel + " is empty."); } else { System.out.println(mapLabel); Iterator iterator = map.keySet().iterator(); int i = 0; while (iterator.hasNext()) { Object key = iterator.next(); Object value = map.get(key); if (key == null) { if (value == null) { System.out.println(i + ": null=null"); } else { System.out.println(i + ": null=" + value.toString()); } } else { if (value == null) { System.out.println(i + ": " + key.toString() + "=null"); } else { System.out.println(i + ": " + key.toString() + "=" + value.toString()); } } i++; } } } }