Java Collection to String collectionToString(Collection list)

Here you can find the source of collectionToString(Collection list)

Description

collection To String

License

Open Source License

Parameter

Parameter Description
list a parameter

Return

the list in csv format

Declaration

public static String collectionToString(Collection<?> list) 

Method Source Code

//package com.java2s;
/*******************************************************************************
* Copyright (c) 2013 Leonardo Aniello, Roberto Baldoni, Leonardo Querzoni.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors://from  www .  j a  v  a  2 s  .c o m
* Leonardo Aniello, Roberto Baldoni, Leonardo Querzoni
*******************************************************************************/

import java.util.Collection;

public class Main {
    /**
     * @param list
     * @return the list in csv format
     */
    public static String collectionToString(Collection<?> list) {
        if (list == null)
            return "null";
        if (list.isEmpty())
            return "<empty list>";
        StringBuffer sb = new StringBuffer();
        int i = 0;
        for (Object item : list) {
            sb.append(item.toString());
            if (i < list.size() - 1)
                sb.append(", ");
            i++;
        }
        return sb.toString();
    }
}

Related

  1. collectionToString(Collection c, String separator)
  2. collectionToString(Collection coll, String connectSymbol)
  3. collectionToString(Collection collection, String separator)
  4. collectionToString(Collection collection, String separator)
  5. collectionToString(Collection elements)
  6. collectionToString(Collection list)
  7. collectionToString(Collection collection, String prefix)
  8. collectionToString(Collection collection)
  9. collectionToString(Collection collection)

  10. HOME | Copyright © www.java2s.com 2016