Java Collection Convert toCommaDelimitedStringInQuotes(Collection c)

Here you can find the source of toCommaDelimitedStringInQuotes(Collection c)

Description

Returns the elements of c separated by commas and enclosed in single-quotes

License

Open Source License

Declaration

public static String toCommaDelimitedStringInQuotes(Collection c) 

Method Source Code

//package com.java2s;
/*/*  w  ww . jav a 2 s  .  c o  m*/
 * Copyright (c) 2016 Vivid Solutions.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * and Eclipse Distribution License v. 1.0 which accompanies this distribution.
 * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
 * and the Eclipse Distribution License is available at
 *
 * http://www.eclipse.org/org/documents/edl-v10.php.
 */

import java.util.Collection;

import java.util.Iterator;

public class Main {
    /**
     *  Returns the elements of c separated by commas and enclosed in
     *  single-quotes
     */
    public static String toCommaDelimitedStringInQuotes(Collection c) {
        StringBuffer result = new StringBuffer();
        for (Iterator i = c.iterator(); i.hasNext();) {
            Object o = i.next();
            result.append(",'" + o.toString() + "'");
        }
        return result.substring(1);
    }
}

Related

  1. toAlphaCollection(Collection collection)
  2. toArray(Collection items, Object array[], boolean convert_to_primitive)
  3. toCollectionString(Collection c, char sep)
  4. toCollectionString(Collection collection_p)
  5. toCommaDelimitedString(Collection c)
  6. toCommaSep(Collection strings)
  7. toCommaSeparatedString(final Collection items)
  8. toCommaSeparatedValues(Collection list)
  9. toCommaSepared(Collection aListOfString)