Java String Join join(String joiner, String... toJoin)

Here you can find the source of join(String joiner, String... toJoin)

Description

join

License

Open Source License

Declaration

public static String join(String joiner, String... toJoin) 

Method Source Code

//package com.java2s;
/**/*from  w  w w  .  j av  a2  s .  c om*/
 * LICENSING
 * 
 * This software is copyright by sunkid <sunkid@iminurnetz.com> and is
 * distributed under a dual license:
 * 
 * Non-Commercial Use:
 *    This program is free software: you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation, either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    This program is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * Commercial Use:
 *    Please contact sunkid@iminurnetz.com
 */

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

public class Main {
    public static String join(String joiner, String... toJoin) {
        return join(joiner, Arrays.asList(toJoin), 0);
    }

    public static String join(String joiner, List<String> toJoin, int start) {
        if (isEmpty(joiner) || toJoin == null || toJoin.size() <= start)
            return "";

        StringBuilder result = new StringBuilder();
        for (int n = start; n < toJoin.size(); n++) {
            result.append(toJoin.get(n));
            result.append(joiner);
        }

        return result.substring(0, result.length() - joiner.length());
    }

    public static String join(String joiner, String[] toJoin, int start) {
        return join(joiner, Arrays.asList(toJoin), start);
    }

    public static boolean isEmpty(String string) {
        return (string == null || string.equals(""));
    }
}

Related

  1. join(String delimiter, String... params)
  2. join(String delimiter, String... strings)
  3. join(String delimiter, T... array)
  4. join(String glue, Iterable items)
  5. join(String glue, String... str)
  6. join(String s, Object... objects)
  7. join(String sep, Object... pieces)
  8. join(String separator, CharSequence... elements)
  9. join(String separator, Collection strings)