Here you can find the source of join(Collection lst, String delim)
Parameter | Description |
---|---|
lst | a parameter |
delim | a parameter |
public static String join(Collection lst, String delim)
//package com.java2s; //License from project: Open Source License import java.util.*; public class Main { /**// ww w . ja v a2 s . c o m * joins a list into a string. similar to methods available IN ANY OTHER LANGUAGE * @param lst * @param delim * @return */ public static String join(Collection lst, String delim) { return joinCol(lst, delim); } public static String join(List lst, String delim) { //this method should not be necessary, but exceptions thrown in test env show that it is.. //strange.. return joinCol((Collection) lst, delim); } /** * split into separate method so we don't get any accidental recursion * between join(list) and join(collection). * @param lst * @param delim * @return */ private static String joinCol(Collection lst, String delim) { StringBuilder builder = new StringBuilder(); for (Object obj : lst) { if (obj != null) builder.append(obj.toString()); builder.append(delim); } builder.delete(builder.length() - delim.length(), builder.length()); return builder.toString(); } }