Here you can find the source of listToStr(Collection a, char sep)
@SuppressWarnings("unchecked") public static String listToStr(Collection a, char sep)
//package com.java2s; /******************************************************************************* * Copyright (c) 2007, 2009 Oracle. 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. * /* w w w . ja v a 2 s.c o m*/ * Contributors: * Oracle - initial API and implementation ******************************************************************************/ import java.util.Collection; import java.util.Iterator; public class Main { @SuppressWarnings("unchecked") public static String listToStr(Collection a, char sep) { return listToStr(a, String.valueOf(sep)); } public static String listToStr(Collection<Object> a, String sep) { //reverse of strToList if (a == null) return null; int count = a.size(); if (count == 0) return null; StringBuffer buffer = null; for (Iterator<Object> iter = a.iterator(); iter.hasNext();) { Object obj = iter.next(); if (obj == null) continue; if (buffer == null) buffer = new StringBuffer(); else buffer.append(sep); if (obj instanceof String) buffer.append((String) obj); else buffer.append(obj); } return (buffer != null) ? buffer.toString() : null; } }