Java Collection Join join(Collection objs, String delim)

Here you can find the source of join(Collection objs, String delim)

Description

join

License

Open Source License

Declaration

public static String join(Collection<?> objs, String delim) 

Method Source Code

//package com.java2s;
//  are made available under the terms of the Eclipse Public License v1.0

import java.util.Collection;

public class Main {
    public static String join(Object[] objs, String delim) {
        if (objs == null) {
            return "";
        }/*from   w w  w  .  j  a v a  2s.c om*/
        StringBuilder ret = new StringBuilder();
        int len = objs.length;
        for (int i = 0; i < len; i++) {
            if (i > 0) {
                ret.append(delim);
            }
            if (objs[i] instanceof String) {
                ret.append('"').append(objs[i]).append('"');
            } else {
                ret.append(objs[i]);
            }
        }
        return ret.toString();
    }

    public static String join(Collection<?> objs, String delim) {
        if (objs == null) {
            return "";
        }
        StringBuilder ret = new StringBuilder();
        boolean needDelim = false;
        for (Object obj : objs) {
            if (needDelim) {
                ret.append(delim);
            }
            if (obj instanceof String) {
                ret.append('"').append(obj).append('"');
            } else {
                ret.append(obj);
            }
            needDelim = true;
        }
        return ret.toString();
    }
}

Related

  1. join(Collection items, String delim)
  2. join(Collection items, String delimiter)
  3. join(Collection iterable, String delimiter)
  4. join(Collection objects, String token, StringBuilder buf)
  5. join(Collection objectsToJoin, String separator)
  6. join(Collection objs, String delim)
  7. join(Collection objs, String delimiter)
  8. join(Collection objs, String sep)
  9. join(Collection s)