Here you can find the source of listToString(List
static <T> String listToString(List<T> list)
//package com.java2s; //License from project: Apache License import java.util.List; import java.util.StringJoiner; public class Main { static <T> String listToString(List<T> list) { if (list == null || list.isEmpty()) return null; StringJoiner joiner = new StringJoiner(",", "[", "]"); for (Object o : list) { if (o == null) joiner.add("null"); else//from ww w . j a v a2s . c om joiner.add(o.toString()); } return joiner.toString(); } private static String toString(Object object) { if (object == null) return null; return String.valueOf(object); } }