• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Enumeration

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 28226
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic