Here you can find the source of join(Iterable
Parameter | Description |
---|---|
strings | The list of strings |
delimiter | The delimiter between strings |
public static String join(Iterable<String> strings, String delimiter)
//package com.java2s; /**/* ww w. j a va 2 s. c o m*/ * Copyright 2011-2016 Three Crickets LLC. * <p> * The contents of this file are subject to the terms of the LGPL version 3.0: * http://www.gnu.org/copyleft/lesser.html * <p> * Alternatively, you can obtain a royalty free commercial license with less * limitations, transferable or non-transferable, directly from Three Crickets * at http://threecrickets.com/ */ import java.util.Iterator; public class Main { /** * Joins a list strings into a single string. * * @param strings * The list of strings * @param delimiter * The delimiter between strings * @return The joined string */ public static String join(String[] strings, String delimiter) { StringBuilder r = new StringBuilder(); for (int i = 0, length = strings.length - 1; i <= length; i++) { r.append(strings[i]); if (i < length) r.append(delimiter); } return r.toString(); } /** * Joins a list strings into a single string. * * @param strings * The list of strings * @param delimiter * The delimiter between strings * @return The joined string */ public static String join(Iterable<String> strings, String delimiter) { StringBuilder r = new StringBuilder(); for (Iterator<String> i = strings.iterator(); i.hasNext();) { r.append(i.next()); if (i.hasNext()) r.append(delimiter); } return r.toString(); } }