Java Collection Create createCSV(Collection list)

Here you can find the source of createCSV(Collection list)

Description

create CSV

License

Open Source License

Declaration

public static String createCSV(Collection list) 

Method Source Code

//package com.java2s;
// Licensed under the Apache License, Version 2.0 (the "License"); you may

import java.util.Collection;

public class Main {
    public static final String EMPTYSTR = "";

    public static String createCSV(Collection list) {
        return createCSV(list, null);
    }/*from ww w .j  ava  2 s .com*/

    public static String createCSV(Collection list, String sep) {
        if (list == null) {
            return null;
        }
        if (sep == null) {
            sep = ", ";
        }
        StringBuilder sb = new StringBuilder();
        for (Object addr : list) {
            sb.append(EMPTYSTR + addr);
            sb.append(sep);
        }

        String s = sb.toString();
        if (s.endsWith(sep)) {
            s = s.substring(0, s.length() - sep.length());
        }

        return s;
    }
}

Related

  1. createCollection(Collection col)
  2. createCollection(Object[] objects)
  3. createCollection(T... items)
  4. createCollection(X o)
  5. createCollectionFromString(String value)
  6. createCsvString(Collection in)
  7. createFloatArray(java.util.Collection collection)
  8. createInstance( Class collectionType)
  9. createIntArray(Collection collection)