Java Collection Join join(Collection objects, String token, StringBuilder buf)

Here you can find the source of join(Collection objects, String token, StringBuilder buf)

Description

join

License

Open Source License

Declaration

public static String join(Collection<?> objects, String token, StringBuilder buf) 

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(Collection<?> objects, String token, StringBuilder buf) {
        for (Iterator<?> it = objects.iterator(); it.hasNext();) {
            buf.append(it.next()).append(token);
        }//  www. j  a  v  a 2 s .c o  m
        buf.delete(buf.lastIndexOf(token), buf.length()); // delete last token
        return buf.toString();
    }

    public static <T> String join(T[] objects, String token, StringBuilder buf) {
        return join(Arrays.asList(objects), token, buf);
    }
}

Related

  1. join(Collection elements, String separator)
  2. join(Collection items, char separator)
  3. join(Collection items, String delim)
  4. join(Collection items, String delimiter)
  5. join(Collection iterable, String delimiter)
  6. join(Collection objectsToJoin, String separator)
  7. join(Collection objs, String delim)
  8. join(Collection objs, String delim)
  9. join(Collection objs, String delimiter)