Java List to String listToString(List list, String glue)

Here you can find the source of listToString(List list, String glue)

Description

list To String

License

Open Source License

Declaration

public static String listToString(List list, String glue) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2014 Gabriel Skantze./* w ww .j  a  v  a  2s  . c om*/
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Public License v3.0
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/gpl.html
 * 
 * Contributors:
 *     Gabriel Skantze - initial API and implementation
 ******************************************************************************/

import java.util.List;

public class Main {
    public static String listToString(List list, String glue) {
        String result = "";
        boolean first = true;
        for (Object item : list) {
            if (!first)
                result += glue;
            result += item.toString();
            first = false;
        }
        return result;
    }

    public static String listToString(List list) {
        return listToString(list, " ");
    }
}

Related

  1. listToString(List list)
  2. listToString(List list)
  3. listToString(List list)
  4. listToString(List list, char sep)
  5. listToString(List list, String delim)
  6. listToString(List list, String prefix, String suffix, String separator)
  7. listToString(List list)
  8. listToString(List list)
  9. listToString(List list, String delim)