Here you can find the source of printList(List
public static <T> String printList(List<T> list)
//package com.java2s; //License from project: Apache License import java.util.List; public class Main { public static <T> String printList(List<T> list) { return printList(list, "[", "]", ", "); }/*from w w w.j a va2s . c o m*/ public static <T> String printList(List<T> list, String prefix, String postfix, String separator) { StringBuilder sb = new StringBuilder(prefix); for (T t : list) { sb.append(t).append(separator); } if (sb.toString().endsWith(separator)) return sb.toString().substring(0, sb.length() - separator.length()) + postfix; return sb.append(postfix).toString(); } }