Java Collection Join joinQuoted(Collection col)

Here you can find the source of joinQuoted(Collection col)

Description

Joins the given list into a string of quoted values joined with ", ".

License

Apache License

Parameter

Parameter Description
col a parameter

Declaration

public static String joinQuoted(Collection<String> col) 

Method Source Code

//package com.java2s;
/**/* w  ww  . j  a  v  a 2  s  .  c om*/
 * 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 {
    /**
     *  Joins the given list into a string of quoted values joined with ", ".
     * @param col
     * @return 
     */
    public static String joinQuoted(Collection<String> col) {

        if (col.isEmpty())
            return "";

        StringBuilder sb = new StringBuilder();
        for (String item : col)
            sb.append(",\"").append(item).append('"');

        String str = sb.toString();
        str = str.replaceFirst(",", "");
        return str;
    }
}

Related

  1. joinCommaDelimitedList(Collection list)
  2. joinEmptyItemIncluded(Collection stringCollection, String delimiter)
  3. joinList(@SuppressWarnings("rawtypes") Collection c)
  4. joinNullSafe(Collection collection, String separator)
  5. joinObjects(Collection objects)
  6. joinSequence(Collection sequence)
  7. joinSort(Collection c, String separator)
  8. joinSorted(Collection s, String delimiter)
  9. joinString(Collection values, String delimiter)

  10. HOME | Copyright © www.java2s.com 2016