Java Collection Concatenate concat(Collection collection, String delimiter)

Here you can find the source of concat(Collection collection, String delimiter)

Description

concat

License

Open Source License

Declaration

public static <E> String concat(Collection<E> collection, String delimiter) 

Method Source Code


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

import java.util.Collection;
import java.util.Iterator;

public class Main {

    public static <E> String concat(Collection<E> collection, String delimiter) {
        if (collection == null) {
            return null;
        }/*from  w  w  w . j  a v a2  s .com*/
        StringBuilder buf = new StringBuilder();
        Iterator<E> itr = collection.iterator();
        while (itr.hasNext()) {
            buf.append(itr.next().toString());
            if (itr.hasNext()) {
                buf.append(delimiter);
            }
        }
        return buf.toString();
    }
}

Related

  1. concat(boolean removeDuplicates, Collection firstCollection, Collection... collections)
  2. concat(Collection> classes, String separator)
  3. concat(Collection c)
  4. concat(Collection items)
  5. concat(Collection parts, int start, String defaultText)
  6. concat(Collection pieces, String delim)