Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

import java.util.Collection;
import java.util.Collections;

import java.util.HashSet;

import java.util.Set;

public class Main {
    public static <A> Set<A> makeSet(Collection<A> xs) {
        if (xs.size() == 0)
            return Collections.<A>emptySet();
        else if (xs.size() == 1)
            return Collections.singleton(xs.iterator().next());
        else {
            Set<A> set = new HashSet<A>(xs.size());
            set.addAll(xs);
            return set;
        }
    }

    @SafeVarargs
    public static <A> Set<A> makeSet(A... xs) {
        if (xs.length == 0)
            return Collections.<A>emptySet();
        else if (xs.length == 1)
            return Collections.singleton(xs[0]);
        else {
            Set<A> set = new HashSet<A>(xs.length);
            Collections.addAll(set, xs);
            return set;
        }
    }
}