Java List Join join(List strings)

Here you can find the source of join(List strings)

Description

Join a list of strings by comma.

License

Open Source License

Parameter

Parameter Description
strings a parameter

Declaration

public static String join(List<String> strings) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.util.List;

public class Main {
    /**//  w  w w  .  j a  v  a 2 s .  com
     * Join a list of strings by comma.
     * @param strings
     * @return
     */
    public static String join(List<String> strings) {
        return join(strings.toArray(new String[0]), ", ");
    }

    /**
     * Join a list of strings by a separator.
     * @param strings
     * @param separator
     * @return
     */
    public static String join(List<String> strings, String separator) {
        return join(strings.toArray(new String[0]), separator);
    }

    /**
     * Join an array of strings by comma.
     * @param strings
     * @return
     */
    public static String join(String[] strings) {
        return join(strings, ", ");
    }

    /**
     * Join an array of strings by a separator.
     * @param strings
     * @param separator
     * @return
     */
    public static String join(String[] strings, String separator) {
        StringBuffer sb = new StringBuffer();
        if (strings.length > 0) {
            sb.append(strings[0]);
            for (int i = 1; i < strings.length; i++) {
                sb.append(separator);
                sb.append(strings[i]);
            }
        }
        return sb.toString();
    }
}

Related

  1. join(List paths)
  2. join(List s, String delim)
  3. join(List s, String sep)
  4. join(List strings)
  5. join(List strings)
  6. join(List strings, String delim)
  7. join(List strings, String delimiter)
  8. join(List strings, String join)
  9. join(List strings, String joiner)