集册 Java实例教程 并集到哈希集

并集到哈希集

欢马劈雪     最近更新时间:2020-01-02 10:19:05

551
并集到哈希集


import java.util.*;
/* 
*来 自
 N  o w  J a v a . c o m
*/


public class Main{

    public static void main(String[] argv){

        Collection collections = java.util.Arrays.asList("asdf","nowjava.com");

        System.out.println(unionToHashSet(collections));

    }

    public static <T> HashSet<T> unionToHashSet(

            final Collection<T>... collections) {

        final HashSet<T> res = new HashSet<T>();

        for (final Collection<T> set : collections) {

            res.addAll(set);

        }

        return res;

    }

    public static <T> HashSet<T> unionToHashSet(

            final Collection<T> collection, final T... items) {

        final HashSet<T> result = 
展开阅读全文