Android Collection Join join(Collection s, String delimiter)

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

Description

perform join operation on specified String collection sperated by specified delimiter

License

Open Source License

Parameter

Parameter Description
s specified String collection
delimiter specified delimiter

Return

String

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 {
    /**//w w w  .  j a  va2  s .c o  m
     * perform join operation on specified String collection sperated by
     * specified delimiter
     * 
     * @param s
     *            specified String collection
     * @param delimiter
     *            specified delimiter
     * @return String
     */
    public static String join(Collection<String> s, String delimiter) {
        if (s == null || s.isEmpty()) {
            return "";
        }

        StringBuilder builder = new StringBuilder();
        Iterator<String> iter = s.iterator();
        while (iter.hasNext()) {
            builder.append(iter.next());
            if (!iter.hasNext()) {
                break;
            }

            builder.append(delimiter);
        }

        return builder.toString();
    }
}

Related

  1. join(Collection collection, String s)
  2. join(Collection strings, String sep)
  3. join(Collection strings, String sep)
  4. join(final Collection strings, String delimeter)
  5. join(Collection collection, String delimiter)
  6. join(CharSequence separator, Collection values)
  7. join(Collection strings, String sep)
  8. write(Collection c, Object separator, Object prefix, Object postfix)