Here you can find the source of listToString(List
public static <T> String listToString(List<T> list, String sep)
//package com.java2s; //License from project: Apache License import java.util.List; public class Main { public static <T> String listToString(List<T> list, String sep) { if (list == null || list.isEmpty()) return null; int size = list.size(); StringBuilder sb = new StringBuilder(); int count = 0; for (T str : list) { sb.append(str.toString());//www .j av a2s .c om if (count < size - 1) sb.append(sep); ++count; } return sb.toString(); } }