Here you can find the source of join(String separator, Collection
Parameter | Description |
---|---|
separator | a parameter |
list | a parameter |
public static String join(String separator, Collection<String> list)
//package com.java2s; import java.util.Collection; public class Main { /**/*from w w w .j a va 2 s. c o m*/ * Converts a {@link Collection} to a <tt>separator<tt> separated string * * @param separator * @param list * @return <tt>separator<tt> separated string version of the given list */ public static String join(String separator, Collection<String> list) { return join(separator, list, null); } /** * Converts a {@link Collection} to a <tt>separator<tt> separated string. * If the <tt>replacement</tt> parameter is not null, it is used to populate * the result string instead of list elements. * * @param separator * @param list * @param replacement * @return <tt>separator<tt> separated string version of the given list */ public static String join(String separator, Collection<String> list, String replacement) { StringBuffer sb = new StringBuffer(); boolean first = true; for (final String s : list) { if (first) first = false; else sb.append(separator); sb.append(replacement == null ? s : replacement); } return sb.toString(); } }