• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Help with the logic

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am working on a problem where in I have 2 Maps with key ,value as String and Object containing all the attributes for the class.
Now some elements in both the maps can be same.
Some can be present in one Map and not in second.
Some can be present in second Map and not in first Map.
The problem is to compare both the Maps.

The logic I am using is.
Take a temp Set say "traversed"
a)Iterate on Map 1.
b)Get the key and


c)So traversed set has all the elements present in Map1
d)Iterate on map2
e)Get the key and


f) here it wont consider values that are present in Map 2 and also in Map 1

The logic seems to be working fine.Just wanted some suggestion on any other way I can handle the situation.

E.g. Map 1
<a,"Harry">
<b,"Potter">
<c,"Hermoine">

Map 2
<a,"Harry1">
<c,"Hermoine1">
<d,"Grenger">
<e,"Ron">

Output should have a Data structure(Class) containing 5 rows

a Harry Harry1
b Potter null
c HerMoine Hermoine1
d null Grenger
e null Ron


Do let me know if I have not made myself Clear.

Thanks in advance
Ankur
 
Marshal
Posts: 80623
469
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don’t understand what you are trying to do. I have not seen a Map with an add() method? Do you mean java.util.Map, or a different sort of Map?
 
Campbell Ritchie
Marshal
Posts: 80623
469
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Go through the Java Tutorials, and find out about the bulk operations. That will allow you to implement S₁ ∪ S₂, S₁ ∩ S₂, S₁ ⊆ S₂, and S₁ \ S₂. etc. You can use S₁ and S₂, as the entry sets of the two maps, or the key or value sets.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic