Here is an example using a simple Set collection:
import java.util.*;The program is called with "java findDups2 (here you would pass the arguments)" The above will return you a list of the Unique words and the duplicate words passed in its arguments.
public class FindDups2 {
public static void main(String[] args) {
Setuniques = new HashSet ();
Setdups = new HashSet ();
for (String a : args)
if (!uniques.add(a))
dups.add(a);
// Destructive set-difference
uniques.removeAll(dups);
System.out.println("Unique words: " + uniques);
System.out.println("Duplicate words: " + dups);
}
}
Based on the above, objects could also be checked for duplicates, or specific members of objects such as id numbers, names, addresses, etc.
Taking mental note of this for future operations...
No comments:
Post a Comment