Here you can find the source of join(List> list, String sep)
Parameter | Description |
---|---|
list | objects to assemble into string. toString() is called on each. |
sep | string to insert between each pair of items |
public static String join(List<?> list, String sep)
//package com.java2s; //License from project: Apache License import java.util.List; public class Main { /**//from w ww . j a v a 2s.c o m * Assemble a list of items into a single string. * * @param list objects to assemble into string. toString() is called on each. * @param sep string to insert between each pair of items * * @return string */ public static String join(List<?> list, String sep) { StringBuffer buf = new StringBuffer(); for (int i = 0; i < list.size(); i++) { if (i > 0) buf.append(sep); buf.append(list.get(i).toString()); } return buf.toString(); } }