Here you can find the source of toString(List> list, char sep)
public static String toString(List<?> list, char sep)
//package com.java2s; //License from project: LGPL import java.util.List; public class Main { private static final int INITIAL_STRING_SIZE = 128; public static final char DEFAULT_SEPARATOR = ','; public static final char DEFAULT_ESCAPE_CHAR = '\\'; public static String toString(List<?> list) { return toString(list, DEFAULT_SEPARATOR, DEFAULT_ESCAPE_CHAR); }//from w ww .ja v a 2 s. c om public static String toString(List<?> list, char sep) { return toString(list, sep, DEFAULT_ESCAPE_CHAR); } public static String toString(List<?> list, char sep, char esc) { if (sep == esc) throw new IllegalArgumentException("separator and escape char are equal"); if (list == null) return null; StringBuilder strBuilder = new StringBuilder(INITIAL_STRING_SIZE); final int size = list.size(); for (int i = 0; i < size; ++i) { if (i > 0) strBuilder.append(sep); Object obj = list.get(i); if (obj != null) { String str = obj.toString(); if (str != null) { final int nrChars = str.length(); for (int j = 0; j < nrChars; ++j) { char c = str.charAt(j); if (c == sep || c == esc) strBuilder.append(esc); strBuilder.append(c); } } } } return strBuilder.toString(); } }