Here you can find the source of listToString(List
public static <T> String listToString(List<T> list)
//package com.java2s; /******************************************************************************* * * Copyright (c) 2008 Fujitsu Services Ltd. * * Author: Nick Battle/*from w ww . j av a 2 s .co m*/ * * This file is part of VDMJ. * * VDMJ is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * VDMJ is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with VDMJ. If not, see <http://www.gnu.org/licenses/>. * ******************************************************************************/ import java.util.List; public class Main { public static <T> String listToString(List<T> list) { return listToString("", list, ", ", ""); } public static <T> String listToString(List<T> list, String separator) { return listToString("", list, separator, ""); } public static <T> String listToString(String before, List<T> list, String separator, String after) { StringBuilder sb = new StringBuilder(); sb.append(before); if (!list.isEmpty()) { sb.append(list.get(0).toString()); for (int i = 1; i < list.size(); i++) { sb.append(separator); sb.append(list.get(i).toString()); } } sb.append(after); return sb.toString(); } }