Here you can find the source of listToString(List
public static String listToString(List<String> list, String separator)
//package com.java2s; //License from project: Open Source License import java.util.*; public class Main { public static String listToString(List<String> list, String separator) { if (list.isEmpty()) { return ""; }//from w w w. j a v a 2 s. c om int n = list.size(); StringBuilder sb = new StringBuilder(); sb.append(list.get(0)); if (n == 1) { return sb.toString(); } for (int i = 1; i < n; i++) { sb.append(separator).append(list.get(i)); } return sb.toString(); } }