get Union of two HashSet - Java Collection Framework

Java examples for Collection Framework:HashSet

Description

get Union of two HashSet

Demo Code


//package com.java2s;

import java.util.HashSet;

public class Main {
    public static <T> HashSet<T> getUnion(HashSet<T> set1, HashSet<T> set2) {
        HashSet<T> set = new HashSet<T>();

        set.addAll(set1);/*from  w  w w  . ja  v  a2s.c  om*/
        set.addAll(set2);
        return set;
    }
}

Related Tutorials