Java List Join join(List list, String delimiter)

Here you can find the source of join(List list, String delimiter)

Description

This method joins together a list of Strings and separates them by a delimiter

License

Open Source License

Parameter

Parameter Description
list List of Strings to join
delimiter String to delimit each item in list

Declaration

public static String join(List<String> list, String delimiter) 

Method Source Code

//package com.java2s;

import java.util.List;

public class Main {
    /**/*from   w w  w. j a  v a 2 s  .c o m*/
     * This method joins together a list of Strings and separates them by a delimiter
     * 
     * @param list
     *            List of Strings to join
     * @param delimiter
     *            String to delimit each item in list
     */
    public static String join(List<String> list, String delimiter) {
        StringBuffer buf = new StringBuffer("");
        if (list != null && list.size() > 0)
            for (int i = 0; i < list.size(); i++)
                if (i == 0)
                    buf.append(list.get(i));
                else
                    buf.append(delimiter).append(list.get(i));

        return buf.toString();

    }
}

Related

  1. join(List list, String conjunction)
  2. join(List list, String delim)
  3. join(List list, String delim)
  4. join(List list, String delimiter)
  5. join(List list, String delimiter)
  6. join(List list, String sep)
  7. join(List list, String separator)
  8. join(List list, String separator)
  9. join(List list1, List list2)