Here you can find the source of join(String delimiter, String... params)
Parameter | Description |
---|---|
delimiter | Delimiter. |
params | The parameters to be joined. |
public static String join(String delimiter, String... params)
//package com.java2s; //License from project: Open Source License import java.util.Arrays; import java.util.List; public class Main { /**/* w w w.j a va2 s . c o m*/ * Joins the given {@code params} using delimiter. * * @param delimiter * Delimiter. * @param params * The parameters to be joined. * @return The joined text. */ public static String join(String delimiter, String... params) { return join(delimiter, Arrays.asList(params)); } /** * Joins the given {@code params} using delimiter. * * @param delimiter * Delimiter. * @param params * The parameters to be joined. * @return The joined text. */ public static String join(String delimiter, List<String> params) { if (params.size() == 0) { return ""; } else if (params.size() == 1) { return params.get(0); } else { StringBuilder sb = new StringBuilder(); sb.append(params.get(0)); for (int i = 1; i < params.size(); ++i) { sb.append(delimiter); sb.append(params.get(i)); } return sb.toString(); } } }