Java tutorial
//package com.java2s; //License from project: Open Source License import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.Set; public class Main { /** line separator. */ private static final String LINE_SEPARATOR = System.lineSeparator(); public static Map<String, String> takeFromSetMap(final Map<String, Set<String>> pMap, final String glue) { final Map<String, String> resMap = new HashMap<String, String>(100); final Iterator<String> iter = pMap.keySet().iterator(); String key; while (iter.hasNext()) { key = iter.next(); resMap.put(key, implode(pMap.get(key), glue)); } return resMap; } public static String implode(final String[] pStrArray) { return implode(pStrArray, "\t"); } public static String implode(final Object[] pieces, final String glue) { final StringBuilder buf = new StringBuilder(110); for (int i = 0; i < pieces.length; i++) { if (0 < i) { buf.append(glue); } buf.append(pieces[i].toString()); } return buf.toString(); } public static String implode(final Iterable<?> pieces) { return implode(pieces, LINE_SEPARATOR); } public static String implode(final Iterable<?> pieces, final String glue) { if (pieces == null) { return ""; } final StringBuilder resBuf = new StringBuilder(100); final Iterator<?> iter = pieces.iterator(); resBuf.append(iter.next().toString()); while (iter.hasNext()) { resBuf.append(glue); resBuf.append(iter.next().toString()); } return resBuf.toString(); } }