Java Map to String toString(Map map)

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

Description

to String

License

Apache License

Parameter

Parameter Description
map a parameter

Declaration

public static String toString(Map<?, ?> map) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

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

public class Main {
    /**//from   w  ww .  j a  va 2  s . c o  m
     * 
     * @param map
     * @return
     */
    public static String toString(Map<?, ?> map) {
        if (map == null || map.size() == 0) {
            return "{ }";
        }

        StringBuffer sb = new StringBuffer();

        sb.append("{");

        Iterator it = map.entrySet().iterator();

        while (it.hasNext()) {
            Map.Entry entry = (Map.Entry) it.next();
            sb.append(entry.getKey());
            sb.append(":");
            sb.append(entry.getValue());
            if (it.hasNext()) {
                sb.append(",");
            }
        }

        sb.append("}");

        return sb.toString();
    }
}

Related

  1. toStr(Map msg)
  2. toString(final Map tokens)
  3. toString(Map varnames_to_Terms)
  4. toString(Map attributes)
  5. toString(Map map)
  6. toString(Map map)
  7. toString(Map m)
  8. toString(Map map)
  9. toString(Map map)