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[] arr, String delim) {
        if (arr == null) {
            return "";
        }/*from   www.j  a  va  2  s  .  c om*/

        return join(arr, 0, arr.length, delim);
    }

    public static String join(Object[] arr, int start, int end, String delim) {
        if (arr == null) {
            return "";
        }
        StringBuilder str = new StringBuilder();
        for (int i = start; i < end; i++) {
            if (i > start) {
                str.append(delim);
            }
            str.append(arr[i]);
        }
        return str.toString();
    }

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

Related

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