Is there a HashMap join elements

dictionary, hashmap, java, join

Solution

Using Google guava-libraries:

Map<String, String> m = new HashMap<String, String>(); 
m.put("lebron", "james");
m.put("kevin", "durant");

Joiner.MapJoiner joiner = Joiner.on(",").withKeyValueSeparator("");
System.out.println(joiner.join(m));  // return lebronjames,kevindurant

Problem

Is there a simple function for joining all elements and key values, to a String ``` Map<String, String> m = new HashMap<String, String>(); m.put("lebron", "james"); m.put("kevin", "durant"); ``` m.join(",") should produce: "lebronjames,kevindurant" I'm looking for a simpler (less verbose) solution using guava or apache common (StringUtils) Java libs, instead of iterating over the map

Original source