Java Map to String toString(Map map)

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

Description

to String

License

Apache License

Declaration

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

Method Source Code


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

import java.util.Map;

public class Main {
    public static <K, V> String toString(Map<K, V> map) {
        if (map == null)
            return "";
        if (map.isEmpty())
            return "{}";

        StringBuilder result = new StringBuilder();
        for (Map.Entry<K, V> entry : map.entrySet()) {
            result.append(String.format(", %s -> %s ", entry.getKey().toString(), entry.getValue().toString()));
        }// w ww  .  j  a v  a  2 s  . c  o  m
        return "{" + result.substring(1) + "}";
    }
}

Related

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