Java Collection Convert convertCollectionStringToCSV(Collection coll, boolean valueInSingleQuotes)

Here you can find the source of convertCollectionStringToCSV(Collection coll, boolean valueInSingleQuotes)

Description

convert Collection String To CSV

License

Apache License

Declaration

public static String convertCollectionStringToCSV(Collection<String> coll, boolean valueInSingleQuotes) 

Method Source Code


//package com.java2s;
/*  /*from   ww  w. jav a 2 s .  c om*/
    
Copyright [2013-2014] eBay Software Foundation
    
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
    
http://www.apache.org/licenses/LICENSE-2.0
    
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
    
*/

import java.util.Collection;

public class Main {
    public static String convertCollectionStringToCSV(Collection<String> coll, boolean valueInSingleQuotes) {

        StringBuffer sb = new StringBuffer();
        int count = 1;
        for (String value : coll) {
            if (valueInSingleQuotes) {
                sb.append("'");
            }
            sb.append(value);
            if (valueInSingleQuotes) {
                sb.append("'");
            }
            if (coll.size() > count) {
                sb.append(",");
            }
            count++;
        }
        return sb.toString();
    }
}

Related

  1. convert(Collection c)
  2. convert2IntegerCollection(String[] strs)
  3. convertArrayInCollection(String[] array)
  4. convertCharCollectionToArray(Collection chars)
  5. convertCollectionInArray(Collection coll)
  6. convertCollectionType(Iterable from, C newCollection, Class listClass)
  7. convertToCollection(Object source)
  8. convertToHqlParameters(Collection numbers)
  9. convertToIntArray(Collection col)