Here you can find the source of joinWithSeparation(String a, String separator, String b)
public static String joinWithSeparation(String a, String separator, String b)
//package com.java2s; import java.util.Iterator; import java.util.Map; public class Main { /**/*from w w w . ja va 2s . com*/ * Appends two strings, inserting separator if either is empty */ public static String joinWithSeparation(String a, String separator, String b) { if (a.length() == 0) return b; if (b.length() == 0) return a; return a + separator + b; } /** * Appends two strings, inserting separator if either is empty. Modifies first map */ public static Map<String, String> joinWithSeparation( Map<String, String> a, String separator, Map<String, String> b) { for (Iterator<String> it = b.keySet().iterator(); it.hasNext();) { String key = it.next(); String bvalue = b.get(key); String avalue = a.get(key); if (avalue != null) { if (avalue.trim().equals(bvalue.trim())) continue; bvalue = joinWithSeparation(avalue, separator, bvalue); } a.put(key, bvalue); } return a; } /** * Type-safe get * @param map * @param key * @return value */ public static <K, V, M extends Map<K, V>> V get(M map, K key) { return map.get(key); } public static boolean equals(Object a, Object b) { return a == b ? true : a == null || b == null ? false : a.equals(b); } }