Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

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

import java.util.HashSet;

import java.util.List;

import java.util.Set;

public class Main {
    public static Set<String> asSet(String[] names) {
        Set<String> set = createHashSet(names.length);
        Collections.addAll(set, names);
        return set;
    }

    public static <K> HashSet<K> createHashSet(int size) {
        return new HashSet<K>(size);
    }

    public static <K> Set<K> createHashSet(K[] ks) {
        Set<K> kSet = new HashSet<K>(ks.length, 1);
        kSet.addAll(Arrays.asList(ks));
        return kSet;
    }

    public static <K> void addAll(Collection<K> destination, Collection<? extends K> toBeAdded) {
        if (destination != null && toBeAdded != null) {
            destination.addAll(toBeAdded);
        }
    }

    public static <K> void addAll(Collection<K> destination, K[] toBeAdded) {
        if (destination != null && toBeAdded != null) {
            Collections.addAll(destination, toBeAdded);
        }
    }

    public static <K> List<K> asList(K... input) {
        if (input == null)
            return null;
        return Arrays.asList(input);
    }
}