Java List Join joinListToString(List lsStr, String sSeparator)

Here you can find the source of joinListToString(List lsStr, String sSeparator)

Description

join List To String

License

Apache License

Declaration

public static String joinListToString(List<? extends Object> lsStr, String sSeparator) 

Method Source Code

//package com.java2s;
/*// w  w w. ja  va2  s . co  m
 * Copyright 2013 SciFY NPO <info@scify.org>.
 *
 * This product is part of the NewSum Free Software.
 * For more information about NewSum visit
 * 
 *    http://www.scify.gr/site/en/our-projects/completed-projects/newsum-menu-en
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 * If this code or its output is used, extended, re-engineered, integrated, 
 * or embedded to any extent in another software or hardware, there MUST be 
 * an explicit attribution to this work in the resulting source code, 
 * the packaging (where such packaging exists), or user interface 
 * (where such an interface exists). 
 * The attribution must be of the form "Powered by NewSum, SciFY"
 */

import java.util.List;

public class Main {
    public static String joinListToString(List<? extends Object> lsStr, String sSeparator) {
        StringBuilder builder = new StringBuilder();
        boolean firstOcc = true; //first occurence
        if (lsStr.size() == 1 && lsStr.get(0).equals("")) {
            return "";
        }
        for (int i = 0; i < lsStr.size(); i++) {
            if (firstOcc) {
                firstOcc = false;
            } else {
                builder.append(sSeparator);
            }
            builder.append(lsStr.get(i).toString());
        }
        return builder.toString();
    }
}

Related

  1. joinList(List parts, String sep)
  2. joinList(String separater, List list)
  3. joinLists( final List> lists)
  4. joinLists(List A, List B, double epsilon)
  5. joinLists(List... list)
  6. joinLong(List lst, String prefix)
  7. joinNiceString(List strings)
  8. joinRecords(List first, List second, String key)
  9. joinRelativePath(List components)