Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.util.Iterator;

public class Main {
    public static String join(final Iterable<String> aContainer) {
        return join(aContainer, "");
    }

    /**
     * Joins a collection of strings to a single string, all parts are merged with a delimiter string.
     *
     * @param aContainer
     * @param aDelimiter
     * @return
     */
    public static String join(final Iterable<String> aContainer, final String aDelimiter) {
        StringBuilder builder = new StringBuilder();
        Iterator<String> it = aContainer.iterator();
        while (it.hasNext()) {
            builder.append(it.next());
            if (it.hasNext())
                builder.append(aDelimiter);
        }
        return builder.toString();
    }
}