Java List Join joinArray(List list, String separator)

Here you can find the source of joinArray(List list, String separator)

Description

Transforms list into a string.

License

Apache License

Declaration

public static <T> String joinArray(List<T> list, String separator) 

Method Source Code


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

import java.util.List;

public class Main {
    /**// w w  w .  j av a  2  s.  co  m
     * Transforms list into a string. It joins the elements of the list with the given separator.
     */
    public static <T> String joinArray(List<T> list, String separator) {
        StringBuilder result = new StringBuilder();
        boolean first = true;

        for (T element : list) {
            if (first) {
                first = false;
            } else {
                result.append(separator);
            }
            result.append(element);
        }
        return result.toString();
    }
}

Related

  1. join(String[] elementList, String separator)
  2. join(String[] list, String separator)
  3. join(T delimiter, List list)
  4. join(T element, List otherElements)
  5. joinAndQuote(char joinChar, char quoteChar, List strings)
  6. joinArrayString(List values)
  7. joinColumnArray(List columnArray)
  8. joinCommaAnd(List objs)
  9. joinCommaSeparatedList(List list)