Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: LGPL 

import java.util.*;

public class Main {
    /**
     * Convenience method to return a Collection as a delimited (e.g. CSV)
     * String. E.g. useful for toString() implementations.
     *
     * @param coll   Collection to display
     * @param delim  delimiter to use (probably a ",")
     * @param prefix string to start each element with
     * @param suffix string to end each element with
     */
    public static String tooDelimitedString(final Collection coll, final String delim, final String prefix,
            final String suffix) {
        if (coll == null) {
            return "";
        }

        final StringBuilder sb = new StringBuilder();
        Iterator it = coll.iterator();
        int i = 0;
        while (it.hasNext()) {
            if (i > 0) {
                sb.append(delim);
            }
            sb.append(prefix).append(it.next()).append(suffix);
            i++;
        }
        return sb.toString();
    }

    public static String toString(final Collection list) {
        final StringBuilder sb = new StringBuilder();
        if (null != list) {
            for (final Object item : list) {
                if (null != item) {
                    sb.append(item);
                }
            }
        }
        return sb.toString();
    }

    public static String toString(final Object[] list) {
        final StringBuilder sb = new StringBuilder();
        if (null != list) {
            for (final Object item : list) {
                if (null != item) {
                    sb.append(item);
                }
            }
        }
        return sb.toString();
    }
}