Here you can find the source of join(Collection
Parameter | Description |
---|---|
s | specified String collection |
delimiter | specified delimiter |
public static String join(Collection<String> s, String delimiter)
//package com.java2s; import java.util.Collection; import java.util.Iterator; public class Main { /**//w w w . j a va2 s .c o m * perform join operation on specified String collection sperated by * specified delimiter * * @param s * specified String collection * @param delimiter * specified delimiter * @return String */ public static String join(Collection<String> s, String delimiter) { if (s == null || s.isEmpty()) { return ""; } StringBuilder builder = new StringBuilder(); Iterator<String> iter = s.iterator(); while (iter.hasNext()) { builder.append(iter.next()); if (!iter.hasNext()) { break; } builder.append(delimiter); } return builder.toString(); } }