Java Collection Join join(Collection collection, CharSequence joinedBy)

Here you can find the source of join(Collection collection, CharSequence joinedBy)

Description

Joins the elements of the provided collection into a single String containing the provided list of elements.

License

Apache License

Declaration

public static <T> String join(Collection<T> collection,
        CharSequence joinedBy) 

Method Source Code

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

import java.util.Collection;

public class Main {
    /**/*ww  w. j a  va 2s . c  o  m*/
     * Joins the elements of the provided collection into a single String containing the provided list of elements.
     * <p>
     * No delimiter is added before or after the list.
     * <p>
     * Empty collections return an empty String.
     */
    public static <T> String join(Collection<T> collection,
            CharSequence joinedBy) {
        if (collection.isEmpty()) {
            return "";
        }
        StringBuilder stringBuilder = new StringBuilder(256);
        for (T t : collection) {
            stringBuilder.append(t.toString()).append(joinedBy);
        }
        return stringBuilder.substring(0,
                stringBuilder.length() - joinedBy.length());
    }
}

Related

  1. join(Collection values)
  2. join(Collection words, String character)
  3. join(Collection c, String concatinator)
  4. join(Collection coll, String separator)
  5. join(Collection collec, String delimiter)
  6. join(Collection collection, String joinString)
  7. join(Collection collections, String separator)
  8. join(Collection list, final String separator)
  9. join(Collection list, String delimiter)