Java Collection Concatenate concatStrings(Collection strings)

Here you can find the source of concatStrings(Collection strings)

Description

Takes Collection of Strings and returns them as a single line of comma separated strings.

License

LGPL

Parameter

Parameter Description
strings a parameter

Declaration

public static String concatStrings(Collection<String> strings) 

Method Source Code

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

import java.util.Collection;

public class Main {
    /**/*w w  w  .  ja v  a2  s .  c  o  m*/
     * Concatenate all String elements using a "," delimiter
     * 
     * @param strings
     * @return single string, with comma separated elements
     */
    public static String concatStrings(String[] strings) {
        StringBuffer buffer = new StringBuffer();
        for (String string : strings) {
            if (buffer.length() > 0) {
                buffer.append(",");
            }
            buffer.append(string);
        }
        return buffer.toString();
    }

    /**
     * Takes Collection of Strings and returns them as a single line of comma separated strings.
     * See {@link #concatStrings(String[])}
     * @param strings
     * @return
     */
    public static String concatStrings(Collection<String> strings) {
        return concatStrings(strings.toArray(new String[strings.size()]));
    }
}

Related

  1. concatenateWithComma(Collection collection)
  2. concatEntries(Collection coll, String sep, String lastSep)
  3. concatInt(Collection collection)
  4. concatNames(Collection cNames, String split)
  5. concatNumber(Collection keys)
  6. concatStrings(Collection values, String separator)
  7. concatStringsWSep(Collection strings, String separator)
  8. concatTokens(Collection tokens)
  9. concatValues(Collection values)