Java List Join join(List list, String joiner)

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

Description

Join the list with joiner.

License

Open Source License

Parameter

Parameter Description
list a list value that need to join.
joiner The joiner that used to join the list.

Return

the joined string.

Declaration

public static <T> String join(List<T> list, String joiner) 

Method Source Code

//package com.java2s;

import java.util.List;

public class Main {
    /**/*w  w w  . j a  va  2 s .c o  m*/
     * Join the list with joiner.
     * @param list a list value that need to join.
     * @param joiner The joiner that used to join the list.
     * @return the joined string.
     * @since 1.0 (TopCoder Direct API Setup and implement My Created Challenges API)
     */
    public static <T> String join(List<T> list, String joiner) {
        StringBuilder stringBuilder = new StringBuilder();
        if (list == null) {
            return null;
        }
        if (list.isEmpty()) {
            return "";
        }
        for (T s : list) {
            stringBuilder.append(s).append(joiner);
        }
        stringBuilder.delete(stringBuilder.length() - joiner.length(),
                stringBuilder.length());
        return stringBuilder.toString();
    }
}

Related

  1. join(List words, String separator)
  2. join(List entries, String separator)
  3. join(List list, String delim)
  4. join(List list, String delim)
  5. join(List list, String delimiter)
  6. join(List list, String separator)
  7. join(List objects, String separator)
  8. join(List objs, String delim)
  9. join(List target, String splite)