Java Collection Join join(Collection elements, String separator)

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

Description

join

License

Creative Commons License

Declaration

public static String join(Collection<? extends Object> elements, String separator) 

Method Source Code

//package com.java2s;
//License from project: Creative Commons License 

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

public class Main {
    public static String join(Collection<? extends Object> elements, String separator) {
        Iterator<? extends Object> iterator = elements.iterator();
        if (iterator.hasNext()) {
            StringBuilder builder = new StringBuilder();
            builder.append(iterator.next().toString());
            while (iterator.hasNext()) {
                builder.append(separator);
                builder.append(iterator.next().toString());
            }// www.  j a  v  a 2s. c  o m
            return builder.toString();
        } else {
            return "";
        }
    }

    public static String join(Collection<? extends Object> elements) {
        return join(elements, "");
    }
}

Related

  1. join(Collection tokens, String separator)
  2. join(Collection var0, Object var1)
  3. join(Collection c, String joinWith)
  4. join(Collection collection, String joinString)
  5. join(Collection collection, String separator)
  6. join(Collection list, String separator)
  7. join(Collection objects, String delim)
  8. join(Collection strings, String separator)
  9. join(Collection strs, String separator)