Java String Join join(String delimiter, String... params)

Here you can find the source of join(String delimiter, String... params)

Description

Joins the given params using delimiter.

License

Open Source License

Parameter

Parameter Description
delimiter Delimiter.
params The parameters to be joined.

Return

The joined text.

Declaration

public static String join(String delimiter, String... params) 

Method Source Code

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

import java.util.Arrays;
import java.util.List;

public class Main {
    /**/*  w  w  w.j  a va2 s .  c o  m*/
     * Joins the given {@code params} using delimiter.
     * 
     * @param delimiter
     *            Delimiter.
     * @param params
     *            The parameters to be joined.
     * @return The joined text.
     */
    public static String join(String delimiter, String... params) {
        return join(delimiter, Arrays.asList(params));
    }

    /**
     * Joins the given {@code params} using delimiter.
     * 
     * @param delimiter
     *            Delimiter.
     * @param params
     *            The parameters to be joined.
     * @return The joined text.
     */
    public static String join(String delimiter, List<String> params) {
        if (params.size() == 0) {
            return "";
        } else if (params.size() == 1) {
            return params.get(0);
        } else {
            StringBuilder sb = new StringBuilder();
            sb.append(params.get(0));
            for (int i = 1; i < params.size(); ++i) {
                sb.append(delimiter);
                sb.append(params.get(i));
            }
            return sb.toString();
        }
    }
}

Related

  1. join(String delimiter, Iterable strings)
  2. join(String delimiter, Iterable strings)
  3. join(String delimiter, Object... objects)
  4. join(String delimiter, Object... parts)
  5. join(String delimiter, String... items)
  6. join(String delimiter, String... strings)
  7. join(String delimiter, T... array)
  8. join(String glue, Iterable items)
  9. join(String glue, String... str)