Here you can find the source of join(List
Parameter | Description |
---|---|
list | a list of strings to join |
delim | the delimiter character(s) to use. (null value will join with no delimiter) |
public static String join(List<Object> list, String delim)
//package com.java2s; //License from project: Open Source License import java.util.Iterator; import java.util.List; public class Main { /**/*from w w w.j a v a 2 s.c o m*/ * Creates a single string from a List of strings seperated by a delimiter. * * @param list * a list of strings to join * @param delim * the delimiter character(s) to use. (null value will join with * no delimiter) * @return a String of all values in the list seperated by the delimiter */ public static String join(List<Object> list, String delim) { if (list == null || list.size() < 1) return null; StringBuffer buf = new StringBuffer(); Iterator<Object> i = list.iterator(); while (i.hasNext()) { buf.append((String) i.next()); if (i.hasNext()) buf.append(delim); } return buf.toString(); } }