Java Collection Print print(Collection c, String separator)

Here you can find the source of print(Collection c, String separator)

Description

print

License

CDDL license

Declaration

public static String print(Collection<?> c, String separator) 

Method Source Code

//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();
    }
}

Related

  1. prettyPrintCollection(Collection collection)
  2. prettyPrintListOfClasses( Collection package1DependenciesOnPackage2)
  3. print(Collection c)
  4. print(Collection c)
  5. print(Collection collection, String delim)
  6. print(Collection c)
  7. print(Collection coll)
  8. print(Collection elements)
  9. print(java.util.Collection collection)