Java List to String listToString(List list)

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

Description

converts a list to a string taking every element and separating them with a , comma.

License

Open Source License

Parameter

Parameter Description
list list to convert

Return

string with all elements separated with , comma

Declaration

public static String listToString(List list) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2008 Mountainminds GmbH & Co. KG
 * This software is provided under the terms of the Eclipse Public License v1.0
 * See http://www.eclipse.org/legal/epl-v10.html.
 *
 * $Id: $//from w  ww .  ja va 2s . c  om
 ******************************************************************************/

import java.util.List;

public class Main {
    /**
     * converts a list to a string taking every element and separating them with
     * a , comma.
     * 
     * @param list
     *            list to convert
     * @return string with all elements separated with , comma
     */
    public static String listToString(List list) {
        StringBuffer result = new StringBuffer();
        for (int i = 0; i < list.size(); i++) {
            result.append(", " + list.get(i));
        }
        return result.substring(2);
    }
}

Related

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