I have TreeMap
which I need to convert to URI-like string and then back to Map.
I need to set custom delimiters.
Is there any tool (Gu
Using Java8:
private static Map prepareMap() {
Map map = new LinkedHashMap<>();
map.put("key1", "val1");
map.put("key2", "val2");
return map;
}
@Test
public void toStr() {
assertEquals("key1_val1|key2_val2", prepareMap().entrySet().stream()
.map(e -> e.getKey() + "_" + e.getValue())
.collect(Collectors.joining("|")));
}
@Test
public void toStrFunction() {
assertEquals("key1_val1|key2_val2", joiner("|", "_").apply(prepareMap()));
}
private static Function