Here you can find the source of collectionToString(Collection> list)
Parameter | Description |
---|---|
list | a parameter |
public static String collectionToString(Collection<?> list)
//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(); } }