Pretty-print a Map in Java

前端 未结 16 1122
傲寒
傲寒 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条回答
  •  一生所求
    2020-12-04 10:47

    Apache libraries to the rescue!

    MapUtils.debugPrint(System.out, "myMap", map);
    

    All you need Apache commons-collections library (project link)

    Maven users can add the library using this dependency:

    
        commons-collections
        commons-collections
        3.2.1
    
    

提交回复
热议问题