Here you can find the source of join(String glue, Collection
toString
of each element in collection with the glue string separating each item
Parameter | Description |
---|---|
T | type of object to join |
glue | the string that will be inserted between elements of items |
items | the elements to join into a string |
public static <T> String join(String glue, Collection<T> items)
//package com.java2s; import java.util.Collection; public class Main { /**/*from ww w .j a va 2 s . c o m*/ * Produces a string that consists of the <code>toString</code> of each element in collection with the glue string separating each item * @param <T> type of object to join * @param glue the string that will be inserted between elements of items * @param items the elements to join into a string * @return a string containing all elements of items separated by glue */ public static <T> String join(String glue, Collection<T> items) { final StringBuilder sb = new StringBuilder(); String join = ""; for (final T item : items) { sb.append(join); join = glue; sb.append(item.toString()); } return sb.toString(); } }