Pretty-print a Map in Java

前端 未结 16 1104
傲寒
傲寒 2020-12-04 10:11

I am looking for a nice way to pretty-print a Map.

map.toString() gives me: {key1=value1, key2=value2, key3=value3}

I

16条回答
  •  -上瘾入骨i
    2020-12-04 10:24

    When I have org.json.JSONObject in the classpath, I do:

    Map stats = ...;
    System.out.println(new JSONObject(stats).toString(2));
    

    (this beautifully indents lists, sets and maps which may be nested)

提交回复
热议问题