[Java Tips] Printing java.util.Map contents

Printing java.util.Map contents is quite a common use case. Most of the time end implementing the same logic of using iterator and writing to Console. Let’s explore a simpler way and taste goodness of Google Guava. Code can be found at MapPrinter.java public static void printMapOnConcole(Map map) { Preconditions.checkNotNull(map); Joiner.MapJoiner mapJoiner = Joiner.on("\n").withKeyValueSeparator("="); System.out.println(mapJoiner.join(map)); } […]

Continue reading