Here you can find the source of join(Iterable
Parameter | Description |
---|---|
iterable | object we can iterate with string values |
delimiter | string used as values splitter |
public static String join(Iterable<String> iterable, String delimiter)
//package com.java2s; //License from project: Apache License import java.util.*; public class Main { /**//from w ww . j a v a 2s . com * Joins content of any Iterable<String> object into string with specified delimiter. * If null or empty object is provided, empty string is returned. * * @param iterable object we can iterate with string values * @param delimiter string used as values splitter * @return joined string or empty string */ public static String join(Iterable<String> iterable, String delimiter) { if (iterable == null) return ""; Iterator<String> i = iterable.iterator(); StringBuilder builder = new StringBuilder(); // append first if (i.hasNext()) builder.append(i.next()); // append rest while (i.hasNext()) { builder.append(delimiter).append(i.next()); } if (builder.length() > 0) return builder.toString(); return ""; } }