Here you can find the source of join(Collection> s, String delimiter)
Parameter | Description |
---|---|
s | The array or list to join. |
delimiter | The delimiter to glue the pieces together with. |
public static String join(Collection<?> s, String delimiter)
//package com.java2s; //License from project: Apache License import java.util.Collection; import java.util.Iterator; public class Main { /**//from w w w. j av a 2 s .co m * Join a string array or list with a delimiter. * * @param s The array or list to join. * @param delimiter The delimiter to glue the pieces together with. * @return The joined string. */ public static String join(Collection<?> s, String delimiter) { StringBuilder builder = new StringBuilder(); Iterator<?> iterator = s.iterator(); while (iterator.hasNext()) { builder.append(iterator.next()); if (!iterator.hasNext()) { break; } builder.append(delimiter); } return builder.toString(); } }