Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions chapter-11/countCommon.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

public static int countCommon(List<Integer> list1, List<Integer> list2) {
/*
Set<Integer> set = new HashSet<Integer>(list1);
Iterator<Integer> i = set.iterator();
int count = 0;
Expand All @@ -16,4 +17,10 @@ public static int countCommon(List<Integer> list1, List<Integer> list2) {
}

return count;
*/
Set<Integer> s1 = new HashSet<>(list1);
Set<Integer> s2 = new HashSet<>(list2);
s1.retainAll(s2);

return s1;
}