Here you can find the source of join(String separator, Iterable
Parameter | Description |
---|---|
separator | character to put between arguments |
args | items to string together |
T | type of items |
public static <T> String join(String separator, Iterable<T> args)
//package com.java2s; // The contents of this file are subject to the Mozilla Public License import java.util.*; public class Main { /**//from w ww.j a v a 2 s . c o m * * @param separator character to put between arguments * @param args items to string together * @param <T> type of items * @return "" for empty array, otherwise arg1 + separator + arg2 + separator + ... */ public static <T> String join(String separator, T... args) { return join(separator, Arrays.asList(args)); } /** * * @param separator character to put between arguments * @param args items to string together * @param <T> type of items * @return "" for empty list, otherwise arg1 + separator + arg2 + separator + ... */ public static <T> String join(String separator, Iterable<T> args) { StringBuilder builder = new StringBuilder(); for (T project : args) { builder.append(project); builder.append(separator); } if (builder.length() > 0) { return builder.substring(0, builder.length() - 1); } else { return ""; } } }