Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Any utility which can print out map quickly

Tags:

java

I am wondering any utility to print out map quickly for debugging purpose.

like image 953
user496949 Avatar asked Apr 12 '11 06:04

user496949


Video Answer


2 Answers

You can just print the toString() of a Map to get a 1-line version of the map, divided up in to key/value entries. If that isn't readable enough, you could do your own looping to print or use Guava to do this:

System.out.println(Joiner.on('\n').withKeyValueSeparator(" -> ").join(map));

That'll give you output of the form

key1 -> value1
key2 -> value2
...
like image 122
ColinD Avatar answered Oct 13 '22 10:10

ColinD


I guess, the .toString() method of implementing class (HashMap or TreeMap for ex.) will do what you want.

like image 32
weekens Avatar answered Oct 13 '22 09:10

weekens