Here you can find the source of join(List
Parameter | Description |
---|---|
strings | The strings to join. |
join | The string to join them with, or null if no string is to be used. |
public static String join(List<String> strings, String join)
//package com.java2s; import java.util.List; public class Main { /**//w ww .ja v a 2s . c o m * Join a list of strings with the given joining string. * * @param strings The strings to join. * @param join The string to join them with, or null if no string is to be used. * @return The string consisting of the strings joined together. */ public static String join(List<String> strings, String join) { StringBuffer buffer = new StringBuffer(); for (int i = 0; i < strings.size(); ++i) { String entry = strings.get(i); buffer.append(entry); if (join != null) { if (i < (strings.size() - 1)) { buffer.append(join); } } } return buffer.toString(); } }