Java Map Print printItems(HashMap map)

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

Description

Listing of all items in a hashmap (useful for formItems

HashMap map Input to iterate over and print items

License

Open Source License

Declaration

public static void printItems(HashMap map) 

Method Source Code


//package com.java2s;
/*/*w  w w. j  a  va2s.  co m*/
 * Copyright 2000-2011 Enonic AS
 * http://www.enonic.com/license
 */

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

public class Main {
    /**
     * Listing of all items in a hashmap (useful for formItems
     * <p/>
     * HashMap map Input to iterate over and print items
     */
    public static void printItems(HashMap map) {
        for (Iterator iter = map.entrySet().iterator(); iter.hasNext();) {
            Map.Entry item = (Map.Entry) iter.next();

            Object value = item.getValue();
            if (value instanceof String[]) {
                String[] list = (String[]) value;
                StringBuffer out = new StringBuffer();
                out.append(item.getKey());
                out.append(" - [");
                for (int i = 0; i < list.length; i++) {
                    Object listItem = list[i];
                    if (listItem == null) {
                        out.append("NULL");
                    } else {
                        out.append(listItem);
                    }

                    if (i < list.length - 1) {
                        out.append(", ");
                    }
                }
                out.append("]");
                System.out.println(out);
            } else {
                System.out.println(item.getKey() + " - " + item.getValue());
            }
        }
    }
}

Related

  1. printHash(HashMap hashMap)
  2. printHash(HashMap hashMap)
  3. printHashMap(String lt, HashMap map, String rt, int maxparm)
  4. printHeaders(Map> headers)
  5. printHttpMessage(String statusLine, Map headers)
  6. printKeys(Map m)
  7. printMap(final Map msg)
  8. printMap(HashMap map)
  9. printMap(Map map)