Here you can find the source of suffixAndJoin(String suffix, String delimiter, Collection
public static <T> String suffixAndJoin(String suffix, String delimiter, Collection<T> values)
//package com.java2s; import java.util.*; public class Main { public static <T> String suffixAndJoin(String suffix, String delimiter, Collection<T> values) { String result = join(suffix + delimiter, values); return isEmpty(result) ? result : result + suffix; }//ww w. j a va2 s.c o m public static <T> String join(String separator, Collection<T> valuesOriginal) { if (valuesOriginal == null) return ""; ArrayList<T> values = new ArrayList<T>(valuesOriginal); removeAllNullEntries(values); if (separator == null) { separator = ""; } if (values.isEmpty()) { return ""; } String joinedString = ""; for (T value : values) { String valueString = value.toString(); if (valueString != null && !isEmpty(valueString)) { joinedString += valueString + separator; } } return isEmpty(joinedString) ? "" : joinedString.substring(0, joinedString.length() - separator.length()); } public static <T> String join(String separator, T... values) { return join(separator, asList(values)); } private static boolean isEmpty(String valueString) { return "".equals(valueString.trim()); } public static void removeAllNullEntries(Collection values) { while (values.remove(null)) ; } public static <T> ArrayList<T> asList(T... values) { ArrayList<T> list = new ArrayList<T>(); for (T value : values) { if (value != null) list.add(value); } return list; } }