Skip to content

Instantly share code, notes, and snippets.

@c9n
Created April 14, 2016 14:14
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 c9n/caddb42eb3721087337d567b689867c7 to your computer and use it in GitHub Desktop.
Save c9n/caddb42eb3721087337d567b689867c7 to your computer and use it in GitHub Desktop.
Set intersection
import java.util.HashSet;
import java.util.Set;
class Untitled {
public static void main(String[] args) {
Set<String> s1 = new HashSet<String>();
s1.add("a");
s1.add("b");
Set<String> s2 = new HashSet<String>();
s2.add("b");
s2.add("c");
s2.add("d");
s1.retainAll(s2);
for (String k : s1) {
System.out.println(k);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment