Here you can find the source of join(Collection extends Object> c, String joinWith)
Parameter | Description |
---|---|
c | a collection of objects |
joinWith | the string that will separate each member of the collection |
public static String join(Collection<? extends Object> c, String joinWith)
//package com.java2s; //License from project: Apache License import java.util.*; public class Main { /**//www .j a v a 2 s . co m * Returns a string consisting of all members of a collection separated * by the specified string. The <code>toString</code> method of each * collection member is called to convert it to a string. * * @param c a collection of objects * @param joinWith the string that will separate each member of the collection */ public static String join(Collection<? extends Object> c, String joinWith) { if (c == null) return ""; StringBuilder buf = new StringBuilder(); boolean first = true; for (Object obj : c) { if (first) first = false; else if (joinWith != null) buf.append(joinWith); buf.append(obj.toString()); } return buf.toString(); } }