Java Map to String mapToString(Map map)

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

Description

Convert a map to a string representation (e.g: for toString())

License

Open Source License

Parameter

Parameter Description
map The map to convert

Return

The string representation of the map

Declaration

public static String mapToString(Map<? extends Object, ? extends Object> map) 

Method Source Code


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

import java.util.Map;

public class Main {
    /**/*from  ww w  . java  2 s  . co m*/
     * Convert a map to a string representation (e.g: for toString())
     * 
     * @param map The map to convert
     * @return The string representation of the map
     */
    public static String mapToString(Map<? extends Object, ? extends Object> map) {
        StringBuilder sb = new StringBuilder();
        if (map == null || map.isEmpty()) {
            return sb.toString();
        }
        for (Object key : map.keySet()) {
            sb.append(key.toString());
            sb.append(" : ");
            sb.append(map.get(key).toString());
            sb.append(" ; ");
        }
        return sb.toString();
    }
}

Related

  1. mapToString(Map map)
  2. mapToString(Map map)
  3. mapToString(Map map)
  4. mapToString(Map map)
  5. mapToString(Map map)
  6. mapToString(Map map)
  7. mapToString(Map map)
  8. mapToString(Map map)
  9. mapToString(Map map)