Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
// The MIT License (MIT)

import java.util.Collections;

import java.util.HashSet;

import java.util.Set;

public class Main {
    @SafeVarargs
    public static <V> Set<V> unmodifiableSet(V... elements) {
        return Collections.unmodifiableSet(toSet(new HashSet<V>(), elements));
    }

    @SafeVarargs
    public static <V> Set<V> unmodifiableSet(Set<V> s, V... elements) {
        return Collections.unmodifiableSet(toSet(s, elements));
    }

    public static <T> Set<T> unmodifiableSet(Set<? extends T> list) {
        if ((list == null) || (list.isEmpty())) {
            return Collections.emptySet();
        }
        return Collections.unmodifiableSet(list);
    }

    @SafeVarargs
    public static <V> Set<V> toSet(V... elements) {
        return toSet(new HashSet<V>(), elements);
    }

    @SafeVarargs
    public static <V> Set<V> toSet(Set<V> s, V... elements) {
        for (V v : elements) {
            s.add(v);
        }
        return s;
    }
}