Java Collection to String toStringWithSeparator(Collection collection, String separator)

Here you can find the source of toStringWithSeparator(Collection collection, String separator)

Description

to String With Separator

License

Apache License

Declaration

public static String toStringWithSeparator(Collection<?> collection,
            String separator) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.Collection;

import java.util.Iterator;

public class Main {
    public static String toStringWithSeparator(Collection<?> collection,
            String separator) {/*from  ww  w  .  j a va2 s . c  om*/
        if (collection.isEmpty())
            return "";

        StringBuilder b = new StringBuilder();
        Iterator<?> it = collection.iterator();
        while (true) {
            b.append(it.next());
            if (it.hasNext()) {
                b.append(separator);
            } else {
                break;
            }
        }
        return b.toString();
    }
}

Related

  1. toStrings(Collection vals)
  2. toStrings(Collection c)
  3. toStrings(Collection objects)
  4. toStrings(final Collection stringCollection)
  5. toStringWithDelimiters(Collection objects, String delim)