Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Enumeration

 
Tim Cerillo
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have two NamingEnumeration instances which contain lastnames. How can I compare these two and search for duplicate lastnames. Thanks.
 
Paul Clapham
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic