Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.util.Iterator;
import java.util.List;

public class Main {
    /**
     * Joins the {@link String} representation of elements of a given list,
     * dividing with a separator.
     * 
     * @param input
     *            - the {@link List} of elements to join.
     * @param separator
     *            - the separator to place between elements
     * @return - the joined {@link String}
     */
    public static <E extends Object> String join(List<E> input, String separator) {
        StringBuilder result = new StringBuilder();
        Iterator<E> it = input.iterator();

        while (it.hasNext()) {
            result.append(it.next());
            if (separator != null && it.hasNext()) {
                result.append(separator);
            }
        }

        return result.toString();
    }
}