Java List Join join(T delimiter, List list)

Here you can find the source of join(T delimiter, List list)

Description

join

License

Open Source License

Declaration

public final static <T> String join(T delimiter, List<T> list) 

Method Source Code

//package com.java2s;
/* FeatureIDE - A Framework for Feature-Oriented Software Development
 * Copyright (C) 2005-2016  FeatureIDE team, University of Magdeburg, Germany
 *
 * This file is part of FeatureIDE./*from   w  w w  . j a va  2s  . c  o  m*/
 * 
 * FeatureIDE is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * FeatureIDE 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 Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with FeatureIDE.  If not, see <http://www.gnu.org/licenses/>.
 *
 * See http://www.fosd.de/featureide/ for further information.
 */

import java.util.List;

public class Main {
    public final static <T> String join(T delimiter, List<T> list) {
        StringBuilder sb = new StringBuilder();
        if (list != null && !list.isEmpty()) {
            for (int i = 0; i < list.size(); i++) {
                sb.append(list.get(i));
                if (i <= list.size() - 1)
                    sb.append(delimiter);
            }
        }
        return sb.toString();
    }
}

Related

  1. join(String separator, List parts)
  2. join(String separator, List parts)
  3. join(String sign, List src)
  4. join(String[] elementList, String separator)
  5. join(String[] list, String separator)
  6. join(T element, List otherElements)
  7. joinAndQuote(char joinChar, char quoteChar, List strings)
  8. joinArray(List list, String separator)
  9. joinArrayString(List values)