Here you can find the source of toString(List> list)
Parameter | Description |
---|---|
list | the list |
public static String toString(List<?> list)
//package com.java2s; /******************************************************************************* * Copyright (c) 2006-2012/*from w ww . ja v a2s.c o m*/ * Software Technology Group, Dresden University of Technology * DevBoost GmbH, Berlin, Amtsgericht Charlottenburg, HRB 140026 * * 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: * Software Technology Group - TU Dresden, Germany; * DevBoost GmbH - Berlin, Germany * - initial API and implementation ******************************************************************************/ import java.util.List; public class Main { /** * @param list the list * @return the list as comma separated string */ public static String toString(List<?> list) { if (list == null) { return "null"; } String listStr = ""; for (Object obj : list) { listStr += obj.toString() + ", "; } listStr = trimLastSeperator(listStr, ", "); return listStr; } /** * @param arg the string * @param sep the separator used in the string * @return the string with the separator trimmed from the end */ public static String trimLastSeperator(String arg, String sep) { if (arg == null || sep == null || arg.equals("") || sep.equals("")) { return ""; } return arg.substring(0, arg.lastIndexOf(sep)); } }