Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.util.*;

public class Main {
    /**
     * Merges the given two lists in a new list, but without duplicates.
     */
    public static <T> List<T> mergeNoDuplicates(List<T> sourceList1, List<T> sourceList2) {
        List<T> ret = alist(sourceList1.size() + sourceList2.size());
        ret.addAll(sourceList1);
        for (T e : sourceList2) {
            if (false == ret.contains(e))
                ret.add(e);
        }
        return ret;
    }

    /**
     * Creates a new empty {@link ArrayList} with the inferred type.
     */
    public static <T> ArrayList<T> alist() {
        return new ArrayList<T>();
    }

    /**
     * Creates a new empty {@link ArrayList} with the inferred type
     * using the given capacity.
     */
    public static <T> ArrayList<T> alist(int initialCapacity) {
        return new ArrayList<T>(initialCapacity);
    }

    /**
     * Creates a new {@link ArrayList} with the inferred type
     * using the given elements.
     */
    public static <T> ArrayList<T> alist(Collection<T> vals) {
        ArrayList<T> ret = new ArrayList<T>(vals.size());
        for (T v : vals)
            ret.add(v);
        return ret;
    }

    /**
     * Creates a new {@link ArrayList} with the inferred type
     * using the given elements.
     */
    @SafeVarargs
    public static <T> ArrayList<T> alist(T... vals) {
        ArrayList<T> ret = new ArrayList<T>(vals.length);
        for (T v : vals)
            ret.add(v);
        return ret;
    }
}