Java String Join join(final Collection input, final String link)

Here you can find the source of join(final Collection input, final String link)

Description

Join parts with link.

License

Open Source License

Parameter

Parameter Description
input a parameter
link a parameter

Declaration

public static <O extends Object> String join(final Collection<O> input, final String link) 

Method Source Code

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

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

public class Main {
    /**/*from   w w  w  . ja  v  a2 s  . c o  m*/
     * Join parts with link, starting from startIndex.
     * @param input
     * @param startIndex
     * @param link
     * @return
     */
    public static <O extends Object> String join(O[] input, int startIndex, String link) {
        return join(Arrays.copyOfRange(input, startIndex, input.length), link);
    }

    /**
     * Join parts with link.
     * 
     * @param input
     * @param link
     * @return
     */
    public static <O extends Object> String join(O[] input, String link) {
        return join(Arrays.asList(input), link);
    }

    /**
     * Join parts with link.
     * 
     * @param input
     * @param link
     * @return
     */
    public static <O extends Object> String join(final Collection<O> input, final String link) {
        final StringBuilder builder = new StringBuilder(Math.max(300, input.size() * 10));
        boolean first = true;
        for (final Object obj : input) {
            if (!first)
                builder.append(link);
            builder.append(obj.toString());
            first = false;
        }
        return builder.toString();
    }
}

Related

  1. join(boolean endSlash, Collection paths)
  2. join(Collection collection, String separator)
  3. join(Collection items, String delimiter)
  4. join(Enumeration enumeration, String s)
  5. join(Enumeration values, CharSequence separator)
  6. join(final String sep, final Iterable strs)
  7. join(final String separator, final Collection objs)
  8. join(final String separator, final String... strings)
  9. join(final String... arguments)