Here you can find the source of join(Collection> objectsToJoin, String separator)
Parameter | Description |
---|---|
objectsToJoin | The objects to join. |
separator | The separator sequence. |
public static String join(Collection<?> objectsToJoin, String separator)
//package com.java2s; //License from project: Apache License import java.util.Collection; public class Main { public final static String EMPTY = ""; public final static String COMMA = ","; /**/*ww w. ja va2 s.c o m*/ * Joins all the strings in the list in a single one separated by the separator sequence. * * @param objectsToJoin The objects to join. * @param separator The separator sequence. * @return The joined strings. */ public static String join(Collection<?> objectsToJoin, String separator) { if ((objectsToJoin != null) && !objectsToJoin.isEmpty()) { StringBuilder builder = new StringBuilder(); for (Object object : objectsToJoin) { builder.append(object); builder.append(separator); } // Remove the last separator return builder.substring(0, builder.length() - separator.length()); } else { return EMPTY; } } /** * Joins all the strings in the list in a single one separated by ','. * * @param objectsToJoin The objects to join. * @return The joined strings. */ public static String join(Collection<?> objectsToJoin) { return join(objectsToJoin, COMMA); } public static Boolean isEmpty(String text) { return text != null ? text.length() == 0 : true; } }