Here you can find the source of concatGenericList(List> list, String delimiter)
Parameter | Description |
---|---|
list | objects toString() representation in the list will be concatenated |
delimiter | this will be printed between the pieces. Will not be printed before and after them. |
public static String concatGenericList(List<?> list, String delimiter)
//package com.java2s; //License from project: Open Source License import java.util.List; public class Main { /**/*ww w.jav a2 s . c o m*/ * Concatenate a list of objects into a * single string. Objects are represented by their toString method * @param list objects toString() representation in the list will be concatenated * @param delimiter this will be printed between the pieces. Will not be printed before and after them. * @return A single string that contains the input list concatenated with delimiters in between */ public static String concatGenericList(List<?> list, String delimiter) { StringBuilder ret = new StringBuilder(); boolean first = true; for (Object s : list) { if (!first) { ret.append(delimiter); } ret.append("" + s); first = false; } return ret.toString(); } }