Java Collection Join join(Collection tokens, String separator)

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

Description

join

License

Open Source License

Declaration

public static String join(Collection tokens, String separator) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.Arrays;
import java.util.Collection;

import java.util.Iterator;

public class Main {
    public static String join(String separator, Object... tokens) {
        return join(Arrays.asList(tokens), separator);
    }/*from   w w w. j av  a2  s.  co  m*/

    public static String join(Collection tokens, String separator) {
        StringBuffer sb = new StringBuffer();
        for (Iterator it = tokens.iterator(); it.hasNext();) {
            Object o = it.next();
            if (o != null) {
                sb.append(o.toString());
            } else {
                sb.append("NULL");
            }
            if (it.hasNext()) {
                sb.append(separator);
            }
        }
        return sb.toString();
    }
}

Related

  1. join(Collection parts, String sep)
  2. join(Collection s, String delimiter)
  3. join(Collection s, String delimiter, boolean doQuote)
  4. join(Collection strings, String sep)
  5. join(Collection strings, String separator)
  6. join(Collection var0, Object var1)
  7. join(Collection c, String joinWith)
  8. join(Collection collection, String joinString)
  9. join(Collection collection, String separator)