Here you can find the source of listToString(List
public static String listToString(List<String> list, String separator)
//package com.java2s; //License from project: Apache License import java.util.List; public class Main { public static String listToString(List<String> list, String separator) { StringBuilder strBuilder = new StringBuilder(); boolean notFirst = false; for (String element : list) { if (element == null || element.trim().length() == 0) { continue; }//www .j a v a2s.c o m if (notFirst) { strBuilder.append(separator); } else { notFirst = true; } strBuilder.append(element); } return strBuilder.toString(); } }