Here you can find the source of join(String separator, String... parts)
Parameter | Description |
---|---|
iterable | the subject |
delimiter | the delimiter |
public static String join(String separator, String... parts)
//package com.java2s; /**//from w w w .j a va2s . c o m * Licensed under Apache License v2. See LICENSE for more information. */ import java.util.Iterator; public class Main { /** * Join an iterable of strings into a single using the specified delimiter. * * @param iterable the subject * @param delimiter the delimiter * @return the join */ public static String join(Iterable<? extends CharSequence> iterable, String delimiter) { Iterator<? extends CharSequence> iter = iterable.iterator(); if (!iter.hasNext()) { return ""; } StringBuilder buffer = new StringBuilder(iter.next()); while (iter.hasNext()) { buffer.append(delimiter).append(iter.next()); } return buffer.toString(); } /** * Join an arry of strings into a single using the specified delimiter. * * @param iterable the subject * @param delimiter the delimiter * @return the join */ public static String join(String separator, String... parts) { StringBuilder builder = new StringBuilder(); for (String part : parts) { if (builder.length() > 0) { builder.append(separator); } builder.append(part); } return builder.toString(); } }