Here you can find the source of join(Collection s, String delimiter, boolean doQuote)
Parameter | Description |
---|---|
s | The String collection |
delimiter | the delimiter String |
doQuote | whether or not to quote the Strings |
public static String join(Collection s, String delimiter, boolean doQuote)
//package com.java2s; //License from project: Apache License import java.util.Arrays; import java.util.Collection; import java.util.Iterator; public class Main { /**//from w w w . j a v a2 s . c o m * Join the array of Strings using the specified delimiter. * * @param s The String array * @param delimiter The delimiter String * @return The joined String */ public static String join(String[] s, String delimiter) { return join(s, delimiter, false); } public static String join(String[] s, String delimiter, boolean doQuote) { return join(Arrays.asList(s), delimiter, doQuote); } /** * Join the Collection of Strings using the specified delimter and * optionally quoting each * @param s The String collection * @param delimiter the delimiter String * @param doQuote whether or not to quote the Strings * @return The joined String */ public static String join(Collection s, String delimiter, boolean doQuote) { StringBuffer buffer = new StringBuffer(); Iterator iter = s.iterator(); while (iter.hasNext()) { if (doQuote) { buffer.append("\"" + iter.next() + "\""); } else { buffer.append(iter.next()); } if (iter.hasNext()) { buffer.append(delimiter); } } return buffer.toString(); } /** * Join the Collection of Strings using the specified delimiter. * * @param s The String collection * @param delimiter The delimiter String * @return The joined String */ public static String join(Collection s, String delimiter) { return join(s, delimiter, false); } }