union two Sets and return a new Set - Java java.util

Java examples for java.util:Set Union

Description

union two Sets and return a new Set

Demo Code


//package com.java2s;

import java.util.HashSet;

import java.util.Set;

public class Main {
    public static <T> Set<T> union(Set<T> set1, Set<T> set2) {
        Set<T> set = new HashSet<>();
        set.addAll(set1);// ww  w  .  j  a va2 s. c o m
        set.addAll(set2);
        return set;
    }
}

Related Tutorials