Here you can find the source of join(String separator, Collection
public static <T> String join(String separator, Collection<T> values)
//package com.java2s; /*!// www . j a va 2 s. c o m * mifmi-commons4j * https://github.com/mifmi/mifmi-commons4j * * Copyright (c) 2015 mifmi.org and other contributors * Released under the MIT license * https://opensource.org/licenses/MIT */ import java.util.Collection; public class Main { public static String join(String separator, Object... values) { return join(new StringBuilder(), separator, values).toString(); } public static StringBuilder join(StringBuilder sb, String separator, Object... values) { if (values == null || values.length == 0) { return sb; } boolean isFirst = true; for (Object value : values) { if (isFirst) { isFirst = false; } else { sb.append(separator); } if (value != null) { sb.append(value.toString()); } } return sb; } public static <T> String join(String separator, Collection<T> values) { return join(new StringBuilder(), separator, values).toString(); } public static <T> StringBuilder join(StringBuilder sb, String separator, Collection<T> values) { if (values == null || values.isEmpty()) { return sb; } return join(sb, separator, values.toArray(new Object[values.size()])); } public static String toString(StringBuilder sb, boolean trim) { if (sb == null) { return null; } if (!trim) { return sb.toString(); } int len = sb.length(); if (len == 0) { return ""; } int sIdx; for (sIdx = 0; sIdx < len; sIdx++) { char ch = sb.charAt(sIdx); if (!Character.isWhitespace(ch)) { break; } } if (sIdx == len) { return ""; } int eIdx; for (eIdx = len - 1; 0 <= eIdx; eIdx--) { char ch = sb.charAt(eIdx); if (!Character.isWhitespace(ch)) { break; } } return sb.substring(sIdx, eIdx + 1); } }