Here you can find the source of listToString(List
public static <E> String listToString(List<E> list)
//package com.java2s; /*//from w w w . j a va2s. c o m Copyright (c) Microsoft Open Technologies, Inc. All Rights Reserved See License.txt in the project root for license information. */ import java.util.List; public class Main { public static <E> String listToString(List<E> list) { return arrayToString(list.toArray()); } public static String arrayToString(Object[] arr) { if (arr == null) { return "<<NULL>>"; } else { StringBuilder sb = new StringBuilder(); sb.append("["); for (int i = 0; i < arr.length; i++) { Object elem = arr[i]; sb.append(elem.toString()); if (i != arr.length - 1) { sb.append(", "); } } sb.append("]"); return sb.toString(); } } }