Here you can find the source of listToString(List
Parameter | Description |
---|---|
l | the list of strings to concatenated into a single string. |
sep | the seperator to inserted between each list element. |
public static String listToString(List<String> l, String sep)
//package com.java2s; /******************************************************************************* * Copyright (c) 2005-2012 Synopsys, Incorporated * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors:// w w w.j av a 2s. co m * Synopsys, Inc - Initial implementation *******************************************************************************/ import java.util.List; public class Main { /** * Alternate to List.toString() that formats the list * as a simple string using a specified string as the * separator between elements. * @param l the list of strings to concatenated into a single string. * @param sep the seperator to inserted between each list element. */ public static String listToString(List<String> l, String sep) { if (l == null) return ""; StringBuffer b = new StringBuffer(); appendListToString(b, l, sep); return b.toString(); } /** * Append a list to a string buffer placing a specified * string between each element. * @param b the string buffer to be filled in. * @param l the list of strings to be appended. * @param sep the seperator to inserted between each list element. */ public static void appendListToString(StringBuffer b, List<String> l, String sep) { if (l != null) { for (String element : l) { b.append(sep); b.append(element); } } } }