Java String Join join(Iterable input)

Here you can find the source of join(Iterable input)

Description

Returns a comma-separated join of the strings in the input.

License

Open Source License

Declaration

public static String join(Iterable<String> input) 

Method Source Code


//package com.java2s;
import java.util.Arrays;

public class Main {
    /**/*from  ww w .  ja  v  a2s.c  om*/
     * Returns a comma-separated join of the strings in the input.
     */
    public static String join(Iterable<String> input) {
        StringBuilder builder = new StringBuilder();
        for (String item : input) {
            builder.append(item).append(", ");
        }
        if (builder.length() >= 2) {
            builder.setLength(builder.length() - 2);
        }
        return builder.toString();
    }

    /**
     * Returns a comma-separated join of the strings in the input.
     */
    public static String join(String[] input) {
        return join(Arrays.asList(input));
    }
}

Related

  1. join(final String separator, final Collection objs)
  2. join(final String separator, final String... strings)
  3. join(final String... arguments)
  4. join(HashMap params, String separator)
  5. join(Iterable arr, String delimeter)
  6. join(java.util.Collection strings, String delimiter)
  7. join(Map map, String separator)
  8. join(String connector, Object... objects)
  9. join(String delim, List strings)