Here you can find the source of join(List
Parameter | Description |
---|---|
list | The list of strings to join |
delim | The string to put inbetween the lists |
public static String join(List<Object> list)
//package com.java2s; //License from project: LGPL import java.util.Arrays; import java.util.List; public class Main { /**//www. j a va2s.c o m * String join helper function * @param list The list of strings to join * @param delim The string to put inbetween the lists */ public static String join(List<Object> list) { return join("", list); } public static String join(Object... list) { return join("", Arrays.asList(list)); } public static String join(String delim, Object... list) { return join(delim, Arrays.asList(list)); } public static String join(String delim, List<Object> list) { StringBuilder sb = new StringBuilder(list.size() > 0 ? list.get(0).toString() : ""); for (int i = 1; i < list.size(); i++) { sb.append(delim); sb.append(list.get(i).toString()); } return sb.toString(); } }