Java Map to String toString(Map map)

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

Description

Returns a string representation of the contents of the specified Map The string representation consists of a list of the Map's entries, enclosed in square brackets ("[]").

License

Open Source License

Parameter

Parameter Description
map the Map whose string representation to return

Return

string representation of map

Declaration

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

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.Map;

public class Main {
    /**//from   w  ww  . jav  a 2s  .co  m
     * Returns a string representation of the contents of the specified Map
     * The string representation consists of a list of the Map's entries,
     * enclosed in square brackets (<tt>"[]"</tt>).
     * Each entry is represented as <tt>key = value</tt>
     *
     * @param map the Map whose string representation to return
     * @return string representation of <tt>map</tt>
     */
    public static String toString(Map<String, String> map) {
        StringBuilder string = new StringBuilder("[");
        for (Map.Entry<String, String> keyValue : map.entrySet()) {
            string.append(keyValue.getKey()).append(" = ").append(keyValue.getValue()).append(";");
        }
        return string.append("]").toString();
    }
}

Related

  1. toString(Map map)
  2. toString(Map map)
  3. toString(Map attrs)
  4. toString(Map attrs)
  5. toString(Map m)
  6. toString(Map params)
  7. toString(Map map)
  8. toString(Map map, StringBuilder sb)
  9. toStringMap( Map enumMap)