Here you can find the source of joinCollection(Collection
Parameter | Description |
---|---|
a | The collection of objects. |
public static String joinCollection(Collection<String> a)
//package com.java2s; //License from project: Open Source License import java.util.Collection; public class Main { /**// w w w . j av a2 s .c o m * Generates a comma-separated string consisting of quoted string representations of a collection of objects. * @param a The collection of objects. * @return The comma-separated string. */ public static String joinCollection(Collection<String> a) { return joinCollection(a, ",", true); } /** * Generates a string consisting of the string representations of a collection of objects. * @param a The array of objects. * @param separator The separator. * @param shouldQuote Flag indicating whether or not the string representations should be quoted. * @return The string. */ public static String joinCollection(Collection<String> a, String separator, boolean shouldQuote) { String result = ""; String quote = shouldQuote ? "\"" : ""; if (a != null && a.size() > 0) { int i = 0; for (Object ai : a) { if (i < a.size() - 1) result += quote + ai + quote + separator; else result += quote + ai + quote; i++; } } return result; } }