I want to be able to (pretty-)print the contents of my maps.
They should have newlines and indentation rather than on a single line; ignoring the toString methods of collections/iterables/etc; and recursing into nested collections.
This is especially of interest for me regarding maps. I suppose JSON'ing might be relevant, but I don't want to go that far, or at least - I don't want my code to have to know about JSON just for me to pretty-print it. What are my options (other than writing this myself)?
You can use the method MapUtils.debugPrint from the apache commons collections in order to print nested maps.
This method prints a nicely formatted String describing the Map. Each map entry will be printed with key, value and value classname. When the value is a Map, recursive behaviour occurs.
Try replacing the start of each entry with new line and tab like this
myMap.toString().replace("[", "\n\t[");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With