Here you can find the source of join(Collection> c, String delimiter)
Parameter | Description |
---|---|
c | the collection to stringify |
delimiter | the character to join on |
public static String join(Collection<?> c, String delimiter)
//package com.java2s; /*// w w w.ja v a 2s. co m * Copyright (C) 2002-2017 FlyMine * * This code may be freely distributed and modified under the * terms of the GNU Lesser General Public Licence. This should * be distributed with the code. See the LICENSE file for more * information or http://www.gnu.org/copyleft/lesser.html. * */ import java.util.Collection; public class Main { /** * Returns a String formed by the delimited results of calling toString over a collection. * * @param c the collection to stringify * @param delimiter the character to join on * @return the string representation */ public static String join(Collection<?> c, String delimiter) { StringBuffer sb = new StringBuffer(); boolean needComma = false; for (Object o : c) { if (needComma) { sb.append(delimiter); } needComma = true; sb.append(o.toString()); } return sb.toString(); } }