Here you can find the source of join(final List
Parameter | Description |
---|---|
strings | a parameter |
delimiter | a parameter |
public static String join(final List<String> strings, final String delimiter)
//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(); } }