Java Array Join join(String[] strings)

Here you can find the source of join(String[] strings)

Description

join

License

Apache License

Parameter

Parameter Description
strings an array of strings

Return

all strings in the given array concatenated. null if the array is null or empty.

Declaration

public static String join(String[] strings) 

Method Source Code

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

import java.util.List;

public class Main {
    /**/* www.j  av  a 2s  .c  om*/
     * @param strings an array of strings
     * @return all strings in the given array concatenated.
     *         null if the array is null or empty.
     */
    public static String join(String[] strings) {
        return join(strings, null);
    }

    /**
     * @param strings an array of strings
     * @param joinString a string (null or empty for nothing)
     * @return all strings in the given array concatenated, with <code>joinString</code> between each.
     *         null if the array is null or empty.
     */
    public static String join(String[] strings, String joinString) {
        if (strings == null || strings.length == 0)
            return null;
        StringBuffer b = new StringBuffer();
        for (String str : strings) {
            if (str != null) {
                b.append(str);
                if (joinString != null)
                    b.append(joinString);
            }
        }
        return b.toString();
    }

    /**
     * @param strings a list of strings
     * @param joinString a string (null or empty for nothing)
     * @return all strings in the given array concatenated, with <code>joinString</code> between each.
     *         null if the array is null or empty.
     */
    public static String join(List<String> strings, String joinString) {
        if (strings == null || strings.size() == 0)
            return null;
        StringBuffer b = new StringBuffer();
        for (String str : strings) {
            if (str != null) {
                b.append(str);
                if (joinString != null)
                    b.append(joinString);
            }
        }
        return b.toString();
    }
}

Related

  1. join(String[] strArray, String delimiter)
  2. join(String[] stringArray, boolean quote, String glue)
  3. join(String[] stringArray, String delimiter)
  4. join(String[] stringArray, String delimiterString, boolean joinNullValues)
  5. join(String[] stringArray, String separator)
  6. join(String[] strings, char delimiter)
  7. join(String[] strings, char delimiter)
  8. join(String[] strings, String glue)
  9. join(String[] strings, String glue)