aspose file tools*
The moose likes Java in General and the fly likes Enumeration Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Enumeration" Watch "Enumeration" New topic
Author

Enumeration

Tim Cerillo
Ranch Hand

Joined: Sep 10, 2002
Posts: 44
I have two NamingEnumeration instances which contain lastnames. How can I compare these two and search for duplicate lastnames. Thanks.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18987
    
    8

Enumerate through them and place the last names into two Set objects. While you are doing that you can check each of the two enumerations to see if it contains duplicates (one interpretation of the question). After you are finished you can compare the two Sets to see if they have any entries in common (another interpretation of the question). There are methods built into the Set API to find intersection and difference.
Tim Cerillo
Ranch Hand

Joined: Sep 10, 2002
Posts: 44
Originally posted by Paul Clapham:
Enumerate through them and place the last names into two Set objects. While you are doing that you can check each of the two enumerations to see if it contains duplicates (one interpretation of the question).


Thanks Paul. This is exactly what I want to do. I'm a java greenhorn, can somebody share some codes to check the two enumerations and find any duplicates? A link to some articles will also help.

Note: The enumerations actually contain unique ids and not lastnames.
[ December 31, 2005: Message edited by: Tim Cerillo ]
uj johansson
Greenhorn

Joined: Dec 31, 2005
Posts: 23

Note: The enumerations actually contain unique ids and not lastnames.


It seems you're looking for the intersection between two sets, the lastnames that are common to both sets?

One way to do this is to load one "enumeration" into a HashSet. Then iterate through the other "enumeration" and check which lastnames are in the HashSet. Place each hit into another HashSet. When you're finished the second HashSet contains the intersection set.
[ December 31, 2005: Message edited by: uj johansson ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Enumeration