Here you can find the source of join(Collection extends Object> strings, String separator)
Parameter | Description |
---|---|
strings | Object objects to stringify and join together |
separator | Separator String string |
public static String join(Collection<? extends Object> strings, String separator)
//package com.java2s; //License from project: Apache License import java.util.*; public class Main { /**/*from w w w .j av a 2 s . co m*/ * Joins the elements of the provided {@link Collection collection} into a * single {@link String string}, using the provided {@code separator} and * string elements. * <p> * For example: <br> * <blockquote> {@code join(asList("foo", "bar"), "*")}<br> * </blockquote> returns<br> * <blockquote> {@code "foo*bar"} </blockquote> * </p> * * @param strings {@link Object objects} to stringify and join together * @param separator Separator {@link String string} * @return String */ public static String join(Collection<? extends Object> strings, String separator) { StringBuilder sb = new StringBuilder(); if (strings != null) { Iterator<? extends Object> i = strings.iterator(); while (i.hasNext()) { sb.append(i.next()); if (i.hasNext()) { sb.append(separator); } } } return sb.toString(); } }