Here you can find the source of print(Collection> c, String separator)
public static String print(Collection<?> c, String separator)
//package com.java2s; /* The contents of this file are subject to the terms * of the Common Development and Distribution License * (the License). You may not use this file except in * compliance with the License.//from w w w . j a v a 2 s .c om * * You can obtain a copy of the License at * http://www.sun.com/cddl/cddl.html or * install_dir/legal/LICENSE * See the License for the specific language governing * permission and limitations under the License. * * When distributing Covered Code, include this CDDL * Header Notice in each file and include the License file * at install_dir/legal/LICENSE. * If applicable, add the following below the CDDL Header, * with the fields enclosed by brackets [] replaced by * your own identifying information: * "Portions Copyrighted [year] [name of copyright owner]" * * $Id$ * * Copyright 2005-2009 Sun Microsystems Inc. All Rights Reserved */ import java.util.*; public class Main { public static String print(Collection<?> c, String separator) { StringBuilder b = new StringBuilder(); if (c.size() <= 0) return ""; Iterator<?> i = c.iterator(); b.append(i.next().toString()); // Fetch first element while (i.hasNext()) { b.append(separator); // separated by separator, b.append(i.next().toString()); // and subsequent elements } return b.toString(); } }