Java List Join join(final List strings, final String delimiter)

Here you can find the source of join(final List strings, final String delimiter)

Description

Joins a list of strings to one string

License

Open Source License

Parameter

Parameter Description
strings a parameter
delimiter a parameter

Return

Joined string

Declaration

public static String join(final List<String> strings, final String delimiter) 

Method Source Code

//package com.java2s;
/**/*from w  w w.ja  va2s. c  om*/
 * This file is part of Atomic Tagging.
 * 
 * Atomic Tagging 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.
 * 
 * Atomic Tagging 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 Atomic Tagging. If not, see
 * <http://www.gnu.org/licenses/>.
 */

import java.util.List;

public class Main {
    /**
     * Joins a list of strings to one string
     * 
     * @param strings
     * @param delimiter
     * @return Joined string
     */
    public static String join(final List<String> strings, final String delimiter) {
        assert strings != null;

        if (strings.isEmpty()) {
            return "";
        }

        boolean first = true;
        final StringBuilder builder = new StringBuilder();

        for (final String string : strings) {
            if (!first) {
                builder.append(delimiter);
            }
            first = false;
            builder.append(string);
        }

        return builder.toString();
    }
}

Related

  1. join(final List array, final String separator)
  2. join(final List data, String separator)
  3. join(final List list)
  4. join(final List list, final String sepa)
  5. join(final List path, final char delimiter)
  6. join(final List strings, final String separator)
  7. join(final List substrings, final String join)
  8. join(final String delimiter, List values)
  9. join(final String separator, final List list)