Collection
Set import java.util.HashSet; import java.util.Set; public class FindDuplicate { public static void main(String[] args) { Set<String> s = new HashSet<String>(); s.add("aman"); s.add("raja"); s.add("raja"); s.add("kumar"); for (String a : args) if (!s.add(a)) System.out.println("Duplicate detected: " + a); System.out.println(s.size() + " distinct words: " + s); } } /* 3 distinct words: [kumar, aman, raja] */ -------------------------------------------------------------------------------------------------------------------------- import java.util.Collection; import java.util.LinkedHashSet; public class SetDuplicate { public static void main(String[] args) { Collection<Integer>noDups=new LinkedHashSet<Integer>(