Java String Join join(final String... arguments)

Here you can find the source of join(final String... arguments)

Description

join

License

Apache License

Declaration

public static String join(final String... arguments) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.Arrays;
import java.util.Map;

public class Main {
    public static final String SPACE = " ";

    public static String join(final String... arguments) {
        return join(
                isEmpty((Object[]) arguments) ? null
                        : Arrays.asList(arguments), SPACE);
    }//from   w ww .  ja  v a2 s . co m

    public static String join(final Iterable<String> arguments) {
        return join(arguments, SPACE);
    }

    public static String join(final Iterable<String> arguments,
            final String delimiter) {
        final StringBuilder buffer = new StringBuilder();
        if (arguments != null) {
            boolean first = true;
            for (final String arg : arguments) {
                if (arg != null) {
                    if (first) {
                        first = false;
                    } else {
                        buffer.append(delimiter);
                    }
                    buffer.append(arg);
                }
            }
        }
        return trimToNull(buffer);
    }

    public static boolean isEmpty(final Object... arguments) {
        return arguments == null || arguments.length == 0;
    }

    public static boolean isEmpty(final Map map) {
        return map == null || map.isEmpty();
    }

    public static String trimToNull(final Object text) {
        if (text != null) {
            final String trim = text.toString().trim();
            return trim.length() > 0 ? trim : null;
        }
        return null;
    }
}

Related

  1. join(Enumeration values, CharSequence separator)
  2. join(final Collection input, final String link)
  3. join(final String sep, final Iterable strs)
  4. join(final String separator, final Collection objs)
  5. join(final String separator, final String... strings)
  6. join(HashMap params, String separator)
  7. join(Iterable arr, String delimeter)
  8. join(Iterable input)
  9. join(java.util.Collection strings, String delimiter)