Java Collection Join join(String separator, Collection c)

Here you can find the source of join(String separator, Collection c)

Description

Returns a string formed by the concatenation of string versions of the elements in a collection, separated by a given separator.

License

Open Source License

Declaration

public static String join(String separator, Collection c) 

Method Source Code

//package com.java2s;

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

public class Main {
    /**//from w w  w  . j a va 2s.  com
     * Returns a string formed by the concatenation of string versions of the
     * elements in a collection, separated by a given separator.
     */
    public static String join(String separator, Collection c) {
        StringBuffer buffer = new StringBuffer();
        Iterator it = c.iterator();
        if (it.hasNext())
            buffer.append(it.next());
        while (it.hasNext())
            buffer.append(separator + it.next());
        return buffer.toString();
    }
}

Related

  1. join(String sep, Collection parts)
  2. join(String sep, Collection values)
  3. join(String sep, Collection values)
  4. join(String sep, Collection strings)
  5. join(String sep, Collection strs)
  6. join(String separator, Collection c)
  7. join(String separator, Collection items)
  8. join(String separator, Collection items)
  9. join(String separator, Collection objs)