Here you can find the source of join(Collection
delimiter
between each String .
Parameter | Description |
---|---|
strings | a parameter |
delimiter | a parameter |
strings
concatenated.
public static String join(Collection<String> strings, String delimiter)
//package com.java2s; //License from project: LGPL import java.util.Arrays; import java.util.Collection; import java.util.Iterator; public class Main { /**/* w ww.j a v a 2 s .c o m*/ * Joins a {@link Collection} of {@link String}s in a single {@link String} * using <code>delimiter</code> between each {@link String}. * * @param strings * @param delimiter * @return a {@link String} with all the {@link String}s in * <code>strings</code> concatenated. */ public static String join(Collection<String> strings, String delimiter) { StringBuffer buffer = new StringBuffer(); Iterator<String> iter = strings.iterator(); while (iter.hasNext()) { buffer.append(iter.next()); if (iter.hasNext()) { buffer.append(delimiter); } } return buffer.toString(); } /** * Joins a array of {@link String}s in a single {@link String} using * <code>delimiter</code> between each {@link String}. * * @param strings * @param delimiter * @return a String */ public static String join(String[] strings, String delimiter) { return join(Arrays.asList(strings), delimiter); } }