Skip to content

Instantly share code, notes, and snippets.

@ryanirilli
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanirilli/ca2ae301df0a1679716f to your computer and use it in GitHub Desktop.
Save ryanirilli/ca2ae301df0a1679716f to your computer and use it in GitHub Desktop.
import java.util.Set;
import java.util.HashSet;
class Test{
public static void main(String[] args){
Set<String> a = new HashSet<String>();
Set<String> b = new HashSet<String>();
a.add("a");
b.add("b");
Set<String> c = union(a, b);
System.out.println(c.size());
}
public static <E> Set<E> union(Set<E> s1, Set<E> s2) {
Set<E> result = new HashSet<E>(s1);
result.addAll(s2);
return result;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment