Here you can find the source of concatenateStrings(List
Parameter | Description |
---|---|
strings | a parameter |
separator | a parameter |
public static String concatenateStrings(List<String> strings, String separator)
//package com.java2s; /**/*from ww w.j av a 2s . c o m*/ * Copyright (c) 2012 eXtensible Catalog Organization * * This program is free software; you can redistribute it and/or modify it * under the terms of the MIT/X11 license. The text of the license can be * found at http://www.opensource.org/licenses/mit-license.php. */ import java.util.*; public class Main { /** * Concatenate the Strings in the List, putting the separator between each but not after the last. * @param strings * @param separator * @return */ public static String concatenateStrings(List<String> strings, String separator) { String result = ""; if (strings != null && !strings.isEmpty()) { StringBuilder sb = new StringBuilder(); for (String s : strings) { sb.append(s).append(separator); } result = sb.toString(); result = result.substring(0, result.length() - separator.length()); } return result; } }