Java Collection Join join(final Collection objs, final String delimiter)

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

Description

join

License

Open Source License

Declaration

public static <T> String join(final Collection<T> objs, final String delimiter) 

Method Source Code

//package com.java2s;
//License from project: GNU General Public License 

import java.util.Collection;

import java.util.Iterator;

public class Main {
    public static <T> String join(final Collection<T> objs, final String delimiter) {
        if (objs == null || objs.isEmpty())
            return "";
        Iterator<T> iter = objs.iterator();
        StringBuffer buffer = new StringBuffer(iter.next().toString());
        while (iter.hasNext())
            buffer.append(delimiter).append(iter.next().toString());
        return buffer.toString();
    }// w  ww  . j  av  a2s  . c om

    public static <T> String join(final Collection<T> objs, final String format, final String delimiter) {
        if (objs == null || objs.isEmpty())
            return "";
        Iterator<T> iter = objs.iterator();
        StringBuffer buffer = new StringBuffer(String.format(format, iter.next().toString()));
        while (iter.hasNext())
            buffer.append(delimiter).append(String.format(format, iter.next().toString()));
        return buffer.toString();
    }
}

Related

  1. join(final Collection toJoin)
  2. join(final Collection values)
  3. join(final Collection values, final char separator)
  4. join(final Collection collection)
  5. join(final Collection collection, final String delimiter)
  6. join(final Collection objs, String delimiter)
  7. join(final String d, final Collection c)
  8. join(final String delimiter, final Collection elements)
  9. join(final String s, final Collection c)