Java List Concatenate concatStrings(List values, String separator)

Here you can find the source of concatStrings(List values, String separator)

Description

Returns concatenated string.

License

Open Source License

Parameter

Parameter Description
values a parameter
separator a parameter

Return

concatenated string.

Declaration

public static String concatStrings(List<String> values, String separator) 

Method Source Code

//package com.java2s;
/*/*ww  w.  j a v a2s .c  om*/
 * Copyright 2015-Present Entando Inc. (http://www.entando.com) All rights reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

import java.util.Iterator;
import java.util.List;

public class Main {
    /**
     * Returns concatenated string.
     * @param values
     * @param separator
     * @return concatenated string.
     */
    public static String concatStrings(List<String> values, String separator) {
        StringBuffer concatedValues = new StringBuffer();
        Iterator<String> valuesIter = values.iterator();
        if (valuesIter.hasNext()) {
            concatedValues.append(valuesIter.next());
            while (valuesIter.hasNext()) {
                concatedValues.append(separator);
                concatedValues.append(valuesIter.next());
            }
        }
        return concatedValues.toString();
    }
}

Related

  1. concatName(String name, List names)
  2. concatNodeList(List list)
  3. concatPathTokens(String root, List tokens)
  4. concatRefs(List refs)
  5. concatString(List args)
  6. concatSuper(List collection1, List collection2)
  7. concatSynopsises( List prefixes, List ss)
  8. concatTwoList(List fromList, List toList)
  9. concatValues(List stringValues, boolean spaceSeparated)