Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//     The contents of this file are subject to the Mozilla Public License

import javax.annotation.Nonnull;

import java.util.*;

public class Main {
    /**
     *
     * @param separator character to put between arguments
     * @param args items to string together
     * @param <T> type of items
     * @return "" for empty array, otherwise arg1 + separator + arg2 + separator + ...
     */
    @Nonnull
    public static <T> String join(String separator, T... args) {
        return join(separator, Arrays.asList(args));
    }

    /**
     *
     * @param separator character to put between arguments
     * @param args items to string together
     * @param <T> type of items
     * @return "" for empty list, otherwise arg1 + separator + arg2 + separator + ...
     */
    @Nonnull
    public static <T> String join(String separator, Iterable<T> args) {
        StringBuilder builder = new StringBuilder();

        for (T project : args) {
            builder.append(project);
            builder.append(separator);
        }

        if (builder.length() > separator.length()) {
            return builder.substring(0, builder.length() - separator.length());
        } else {
            return "";
        }
    }
}