Java Collection Join join(Collection s, String delimiter)

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

Description

Join a collection of objects into a single string string separated by a delimiter

License

Open Source License

Declaration

public static String join(Collection<String> s, String delimiter) 

Method Source Code


//package com.java2s;
import java.util.Collection;
import java.util.Iterator;

public class Main {
    /**/*from  w  ww  .  j  a  v a  2s  .c o  m*/
     * Join a collection of objects into a single string string separated by a
     * delimiter
     * 
     * @note see http://snippets.dzone.com/posts/show/91
     */
    public static String join(Collection<String> s, String delimiter) {
        if (s.isEmpty())
            return "";

        Iterator<String> iter = s.iterator();
        StringBuffer buffer = new StringBuffer(iter.next());

        while (iter.hasNext())
            buffer.append(delimiter).append(iter.next());

        return buffer.toString();
    }
}

Related

  1. join(Collection items, String prefix, String suffix, String itemPrefix, String itemSuffix)
  2. join(Collection list)
  3. join(Collection list, String conjunction)
  4. join(Collection packs)
  5. join(Collection s, String delimiter)
  6. join(Collection src, String delim)
  7. join(Collection strings)
  8. join(Collection strings, String delimiter)
  9. join(Collection strings, String delimiter)