Here you can find the source of join(String delimiter, String... strings)
Parameter | Description |
---|---|
delimiter | The delimiter to place between the individual strings. |
strings | The strings to be joined. |
public static String join(String delimiter, String... strings)
//package com.java2s; /**//w ww . java2s .c om * Copyright (C) 2002-2015 The FreeCol Team * * This file is part of FreeCol. * * FreeCol 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 2 of the License, or * (at your option) any later version. * * FreeCol 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 FreeCol. If not, see <http://www.gnu.org/licenses/>. */ import java.util.List; public class Main { /** * Joins the given strings. * * In Java 8, we can use String.join. * * @param delimiter The delimiter to place between the individual strings. * @param strings The strings to be joined. * @return Each of the strings in the given array delimited by the given * string. */ public static String join(String delimiter, String... strings) { if (strings == null || strings.length == 0) { return null; } else { StringBuilder result = new StringBuilder(strings[0]); for (int i = 1; i < strings.length; i++) { result.append(delimiter); result.append(strings[i]); } return result.toString(); } } /** * Joins the given strings. * * @param delimiter The delimiter to place between the individual strings. * @param strings The strings to be joined. * @return Each of the strings in the given array delimited by the given * string. */ public static String join(String delimiter, List<String> strings) { return join(delimiter, strings.toArray(new String[0])); } }