diff --git a/chapter-11/countCommon.java b/chapter-11/countCommon.java index 2aae1e4..8bde43d 100644 --- a/chapter-11/countCommon.java +++ b/chapter-11/countCommon.java @@ -5,6 +5,7 @@ */ public static int countCommon(List list1, List list2) { + /* Set set = new HashSet(list1); Iterator i = set.iterator(); int count = 0; @@ -16,4 +17,10 @@ public static int countCommon(List list1, List list2) { } return count; + */ + Set s1 = new HashSet<>(list1); + Set s2 = new HashSet<>(list2); + s1.retainAll(s2); + + return s1; }