How can I dump the contents of a Java HashMap(or any other), for example to STDOUT ?
As an example, suppose that I have a complex HashMap of the following structure
A good way to dump data structures (e.g. made of nested maps, arrays and sets) is by serializing it to formatted JSON. For example using Gson (com.google.gson):
Gson gson = new GsonBuilder().setPrettyPrinting().create();
System.out.println(gson.toJson(dataStructure));
This will print out the most complex data structures in a fairly readable way.