Here you can find the source of createCsvString(Collection
Parameter | Description |
---|---|
in | collection to format |
null
if in
is null
, CSV string in other cases (empty id in is empty)
public static String createCsvString(Collection<String> in)
//package com.java2s; import java.util.Collection; public class Main { /**/*from www .ja v a 2s.c o m*/ * Create string with comma separated list of values from input collection. Ordering by used Collection implementation * iteration order is used. * * @param in collection to format * @return <code>null</code> if <code>in</code> is <code>null</code>, CSV string in other cases (empty id in is empty) */ public static String createCsvString(Collection<String> in) { if (in == null) return null; if (in.isEmpty()) { return ""; } boolean first = true; StringBuilder sb = new StringBuilder(); for (String s : in) { if (first) first = false; else sb.append(","); sb.append(s); } return sb.toString(); } /** * Check if String value is null or empty. * * @param src value * @return <code>true</code> if value is null or empty */ public static boolean isEmpty(String src) { return (src == null || src.length() == 0 || src.trim().length() == 0); } }