Java Collection Join join(Collection s)

Here you can find the source of join(Collection s)

Description

Concatenate a Collection of Strings using the given delimiter.

License

Open Source License

Declaration

public static String join(Collection<?> s) 

Method Source Code


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

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

public class Main {
    /**//www.  j  a  v  a2s .  c  o m
     * Concatenate a Collection of Strings using the given delimiter.
     */
    public static String join(Collection<?> s) {
        if (s == null)
            return "";
        StringBuilder buffer = new StringBuilder();
        Iterator<?> iter = s.iterator();
        while (iter.hasNext()) {
            Object item = iter.next();
            if (item != null) {
                buffer.append(item);
                if (iter.hasNext()) {
                    buffer.append(", ");
                }
            }

        }
        return buffer.toString();
    }
}

Related

  1. join(Collection objectsToJoin, String separator)
  2. join(Collection objs, String delim)
  3. join(Collection objs, String delim)
  4. join(Collection objs, String delimiter)
  5. join(Collection objs, String sep)
  6. join(Collection s, String delimiter)
  7. join(Collection s, String delimiter)
  8. join(Collection s, String delimiter)
  9. join(Collection strings, String delimiter)