Here you can find the source of listToString(List
public static String listToString(List<Object> list, String operator)
//package com.java2s; //License from project: Open Source License import java.util.*; public class Main { public static String listToString(List<Object> list, String operator) { StringBuilder stringBuilder = new StringBuilder(); if (isNotEmpty(list)) { for (Object object : list) { if (null != object) { stringBuilder.append(object); }//from w w w . j a v a2 s. co m if (!object.equals(list.get(list.size() - 1))) { stringBuilder.append(operator); } } } return stringBuilder.toString(); } public static boolean isNotEmpty(Map<?, ?> map) { if (null != map && map.size() > 0) return true; return false; } public static boolean isNotEmpty(Collection<?> collection) { return !isEmpty(collection); } public static Map<Object, Object> get(List<Map<Object, Object>> list, Object key) { for (Map<Object, Object> map : list) { if (map.containsKey(key)) { return map; } } return null; } public static boolean isEmpty(Collection<?> collection) { if (null == collection || collection.isEmpty() || collection.size() <= 0) return true; return false; } public static boolean isEmpty(Map<?, ?> map) { if (null == map || map.isEmpty() || map.size() <= 0) return true; return false; } }