Here you can find the source of join(Collection> collection, String delimiter)
Parameter | Description |
---|---|
collection | collection of elements |
delimiter | string to insert between elements |
public static String join(Collection<?> collection, String delimiter)
//package com.java2s; import java.util.Collection; public class Main { /**// w ww .j a v a 2 s. com * Joins the elements of a collection together into one string. * * @param collection collection of elements * @param delimiter string to insert between elements * @return joined string */ public static String join(Collection<?> collection, String delimiter) { return join(collection, delimiter, "%s"); } /** * Joins the elements of a collection together into one string with some * format string. * * @param collection collection of elements * @param delimiter string to insert between elements * @param format format string for elements * @return joined string */ public static String join(Collection<?> collection, String delimiter, String format) { StringBuilder str = new StringBuilder(); for (Object element : collection) { if (str.length() > 0) str.append(delimiter); str.append(String.format(format, element)); } return str.toString(); } }