Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

import java.util.Collection;

import java.util.Iterator;

public class Main {
    /**
     * Prints each object in the collection with commas between them.
     * Nulls will print as "null".  A null collection will cause NPE.
     */
    public static String collectionToString(Collection col) {
        StringBuffer outputString = new StringBuffer(100);
        boolean firstItem = true;
        Iterator it = col.iterator();
        while (it.hasNext()) {
            if (!firstItem)
                outputString.append(", ");
            outputString.append(it.next());
            firstItem = false;
        }
        return outputString.toString();
    }
}