Java Collection Join join(Collection s, String delimiter, boolean doQuote)

Here you can find the source of join(Collection s, String delimiter, boolean doQuote)

Description

Join the Collection of Strings using the specified delimter and optionally quoting each

License

Apache License

Parameter

Parameter Description
s The String collection
delimiter the delimiter String
doQuote whether or not to quote the Strings

Return

The joined String

Declaration

public static String join(Collection s, String delimiter,
        boolean doQuote) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;

public class Main {
    /**//from w w  w . j a  v a2  s . c o m
     * Join the array of Strings using the specified delimiter.
     *
     * @param s The String array
     * @param delimiter The delimiter String
     * @return The joined String
     */
    public static String join(String[] s, String delimiter) {
        return join(s, delimiter, false);
    }

    public static String join(String[] s, String delimiter, boolean doQuote) {
        return join(Arrays.asList(s), delimiter, doQuote);
    }

    /**
     * Join the Collection of Strings using the specified delimter and
     * optionally quoting each
     * @param s The String collection
     * @param delimiter the delimiter String
     * @param doQuote whether or not to quote the Strings
     * @return The joined String
     */
    public static String join(Collection s, String delimiter,
            boolean doQuote) {
        StringBuffer buffer = new StringBuffer();
        Iterator iter = s.iterator();
        while (iter.hasNext()) {
            if (doQuote) {
                buffer.append("\"" + iter.next() + "\"");
            } else {
                buffer.append(iter.next());
            }
            if (iter.hasNext()) {
                buffer.append(delimiter);
            }
        }
        return buffer.toString();
    }

    /**
     * Join the Collection of Strings using the specified delimiter.
     *
     * @param s The String collection
     * @param delimiter The delimiter String
     * @return The joined String
     */
    public static String join(Collection s, String delimiter) {
        return join(s, delimiter, false);
    }
}

Related

  1. join(Collection lst, String delim)
  2. join(Collection objects, String glue)
  3. join(Collection paramCollection, String paramString)
  4. join(Collection parts, String sep)
  5. join(Collection s, String delimiter)
  6. join(Collection strings, String sep)
  7. join(Collection strings, String separator)
  8. join(Collection tokens, String separator)
  9. join(Collection var0, Object var1)