联合HashSet使用

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

public class UnionToHashSet {

public static void main(String[] args) {
    // TODO Auto-generated method stub
    Collection collections = java.util.Arrays.asList("asdf","java");
    System.out.println(unionToHashSet(collections));
}
public static  HashSet unionToHashSet(
        final Collection... collections) {
    final HashSet res = new HashSet();
    for (final Collection set : collections) {
        res.addAll(set);
    }
    return res;
}
public static  HashSet unionToHashSet(
        final Collection collection, final T... items) {
    final HashSet result = new HashSet();
    result.addAll(collection);
    Collections.addAll(result, items);
    return result;
}

}
Console:
[java, asdf]

你可能感兴趣的:(联合HashSet使用)